Chciałbym zapewnić implementację szablonu w moim module i pozwolić motywom na zastąpienie go. Zasadniczo dodaję sugestię za pomocą tego uproszczonego kodu:
function attach_preprocess_node(&$vars) {
$vars['theme_hook_suggestions'][] = 'node__test';
}
(Nie chcę używać hook_theme do dodawania nowego motywu, ponieważ chcę ponownie użyć funkcji węzła preprocesowania. Nazwa motywu jest niezręczna, ale nie chcę pisać node_ attach _%, aby uniknąć pomyłki z typem węzła).
Następnie używam hook_theme_registry_alter (), aby dodać ścieżkę modułu:
function attach_theme_registry_alter(&$theme_registry) {
$path = drupal_get_path('module', 'attach') . '/themes';
$theme_registry_copy = $theme_registry;
_theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'node', drupal_get_path('module', 'node'));
$theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
if (!isset($theme_registry['node']['theme paths'])) {
$theme_registry['node']['theme paths'] = array();
}
if (!isset($theme_registry['node']['theme paths'])) {
$first_element = array_shift($theme_registry['node']['theme paths']);
if ($first_element) {
array_unshift($theme_registry['node']['theme paths'], $first_element, $path);
}
else {
array_unshift($theme_registry['node']['theme paths'], $path);
}
}
}
Jednak to nie działa. To znaczy: plik themes / node - super.tpl.php nie jest używany. Jest używany tylko wtedy, gdy skopiowałem go do folderu motywu.