$items[‘items‘] = array( l(‘Configure‘, ‘admin/config‘), l(‘Structure‘, ‘admin/structure‘), ); $theme = theme(‘item_list‘, $items);
1, 判断是否所有的模块都加载了,
if (!module_load_all(NULL) && !defined(‘MAINTENANCE_MODE‘)) { throw new Exception(t(‘theme() may not be called until all modules are loaded.‘)); }
2, 获得所有的ThemeRegistry信息, 这个信息就是所有模块定义的hook_theme的数组, 并合并了很多默认的信息, 比如process function, function, render array, variables,etc
$hooks = theme_get_registry(FALSE);
3, 获得这次的ThemeHook所对应的ThemeRegistry信息
$info = $hooks[$hook];
4, 如果hook_theme定义了includes, 那就加载函数
if (!empty($info[‘includes‘])) { foreach ($info[‘includes‘] as $include_file) { include_once DRUPAL_ROOT . ‘/‘ . $include_file; } }
5, 吧$variable和ThemeRegistry对应这次hook的variable合并
if (!empty($info[‘variables‘])) { $variables += $info[‘variables‘]; }
6, $info里面process preprocess function被调用
$processor_function($variables, $hook_clone);
7, 如果在process preprocess function里改变了$variable[‘theme_hook_suggestion‘]的话, 会重新加载$hook
$info = $hooks[$suggestion];
8, $info里面的function会被调用来处理$variable
$output = $info[‘function‘]($variables);
theme('item-list',array('items'=>array('aaa','bbb'))) 是如何运行的 ?
时间: 2024-12-26 18:40:58