的Drupal 7有一個鉤子,允許模塊目前正在改變啓用主題:hook_custom_theme()。
請注意,用於調用該鉤子的代碼如下所示。 (見menu_get_custom_theme())
// First allow modules to dynamically set a custom theme for the current
// page. Since we can only have one, the last module to return a valid
// theme takes precedence.
$custom_themes = array_filter(module_invoke_all('custom_theme'), 'drupal_theme_access');
if (!empty($custom_themes)) {
$custom_theme = array_pop($custom_themes);
}
// If there is a theme callback function for the current page, execute it.
// If this returns a valid theme, it will override any theme that was set
// by a hook_custom_theme() implementation above.
$router_item = menu_get_item();
if (!empty($router_item['access']) && !empty($router_item['theme_callback']) && function_exists($router_item['theme_callback'])) {
$theme_name = call_user_func_array($router_item['theme_callback'], $router_item['theme_arguments']);
if (drupal_theme_access($theme_name)) {
$custom_theme = $theme_name;
}
}
由於系統模塊實現了鉤子,如果你的情況下鉤首先執行一個模塊中實現hook_custom_theme()
(例如,模塊的簡稱是custom_module),那麼系統模塊可以覆蓋您的模塊設置的主題。
通常,設置全局$custom_theme
應該會得到相同的效果。確保已設置的主題已啓用。
嘗試添加'global $ custom_theme; $ custom_theme ='theme_name';'到你的'hook_cron()'實現的頂部 – Clive
這似乎沒有進入Drupal 7,但是在從Drupal 6中找到API入口時,我發現一個Drupal 7掛鉤用於設置主題:http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_custom_theme/7 – curiouser