Drupal Features include Theme

痴心易碎 提交于 2019-12-23 08:36:48

问题


Is it possible to include a theme in a Drupal Feature? if so how?


回答1:


Not at the moment, unfortunately. Features basically consist of things that can be cleanly exported out of and imported into Drupal via various event hooks. Themes are an entirely different animal.

Theoretically, if you want to override some markup in your Feature (custom tpl.php files for your own content type for example), you could include the custom tpl.php file and use theme-related hooks in the Feature's module file to let Drupal know that the templates are in your module's directory.




回答2:


In addition to Eaton's answer. If you need to override an existing template (a .tpl.php file) provided by another module you can use hook_theme_registry_alter in YOUR_FEATURE.module:

function YOUR_FEATURE_registry_alter($theme_registry) {
  $originalpath = array_shift($theme_registry['TEMPLATE']['theme paths']);
  $featurepath = drupal_get_path('module', 'YOUR_FEATURE') .'/themes');
  array_unshift($theme_registry['TEMPLATE']['theme paths'], $originalpath, $featurepath);
}

In order for this to work, your feature should have a weight greater than the one of the module providing the overrided template. So in YOUR_FEATURE.install you will have something like

function YOUR_FEATURE_install() {
   db_query("UPDATE {system} SET weight = 10 WHERE name = 'YOUR_FEATURE'");
}


来源:https://stackoverflow.com/questions/3024423/drupal-features-include-theme

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!