0

cronの実行中に、多くのノードのマークアップをキャッシュするモジュールがあります。私の問題は、このcronの実行中に、レンダリング関数からのマークアップがテーマフックまたはテンプレートを通過しないことです。

モジュールコード内から、どのようにテーマを選択できますか?フックはありますか?指定できる機能はありますか?

最終的には、これを実行して、page_buildフックでこれを実行しているかのように同じ結果を取得できるようにしたいと考えています。

render(node_view($node, 'teaser'));
render(node_view($node, 'mini_teaser'));
4

1 に答える 1

0

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を設定すると同じ効果が得られます。設定されているテーマが有効になっていることを確認してください。

于 2013-01-21T01:26:25.630 に答える