theme_breadcrumb is provide by theme.inc, in module breadcrumb2(http://drupal.org/project/breadcrumb2 ), I change it to a template file by using hook_theme_registry_alter. In a project, I copy breacrumb.tpl.php to theme directory, try to override it in theme layer, after i clear the cache again and again, it still does not work. Here is my code:
/**
* Implements hook_theme_registry_alter().
*/
function breadcrumb2_theme_registry_alter(&$theme_registry) {
if (isset($theme_registry['breadcrumb'])) {
$path = drupal_get_path('module', 'breadcrumb2');
$theme_registry['breadcrumb']['path'] = $path;
$theme_registry['breadcrumb']['template'] = 'breadcrumb';
$theme_registry['breadcrumb']['function'] = NULL;
}
}
Although it was fixed in latest version of breadcrumb2 module, I still think that this is bug of drupal core. Other developers have the same experience when they implement hook_theme_registry_alter, Most of them do not know how to fix it.
Sollutions:
(1),fix it in drupal core, using following code instead:
function _theme_build_registry($theme, $base_theme, $theme_engine) {
$cache = array();
// First, process the theme hooks advertised by modules. This will
// serve as the basic registry. Since the list of enabled modules is the same
// regardless of the theme used, this is cached in its own entry to save
// building it for every theme.
if ($cached = cache_get('theme_registry:build:modules')) {
$cache = $cached->data;
}
else {
foreach (module_implements('theme') as $module) {
_theme_process_registry($cache, $module, 'module', $module, drupal_get_path('module', $module));
}
// Only cache this registry if all modules are loaded.
if (module_load_all(NULL)) {
cache_set('theme_registry:build:modules', $cache);
}
}
// Let modules alter the registry.
drupal_alter('theme_registry', $cache);
// Process each base theme.
foreach ($base_theme as $base) {
// If the base theme uses a theme engine, process its hooks.
$base_path = dirname($base->filename);
if ($theme_engine) {
_theme_process_registry($cache, $theme_engine, 'base_theme_engine', $base->name, $base_path);
}
_theme_process_registry($cache, $base->name, 'base_theme', $base->name, $base_path);
}
// And then the same thing, but for the theme.
if ($theme_engine) {
_theme_process_registry($cache, $theme_engine, 'theme_engine', $theme->name, dirname($theme->filename));
}
// Finally, hooks provided by the theme itself.
_theme_process_registry($cache, $theme->name, 'theme', $theme->name, dirname($theme->filename));
// Optimize the registry to not have empty arrays for functions.
foreach ($cache as $hook => $info) {
foreach (array('preprocess functions', 'process functions') as $phase) {
if (empty($info[$phase])) {
unset($cache[$hook][$phase]);
}
}
}
return $cache;
}
(2), Dirty way to fix it in breadcrumb2:
/**
* Implements hook_theme_registry_alter().
*/
function breadcrumb2_theme_registry_alter(&$theme_registry) {
if (isset($theme_registry['breadcrumb'])) {
$path = drupal_get_path('module', 'breadcrumb2');
$theme_registry['breadcrumb']['path'] = $path;
$theme_registry['breadcrumb']['template'] = 'breadcrumb';
$theme_registry['breadcrumb']['function'] = NULL;
}
global $theme;
$themes = list_themes();
$theme_obj = $themes[$theme];
_theme_process_registry($theme_registry, 'phptemplate', 'theme_engine', $theme_obj->name, dirname($theme_obj->filename));
}
I have to recall _theme_process_registry by myself.
Comment | File | Size | Author |
---|---|---|---|
#1 | theme-registry-alter-1873856-1.patch | 963 bytes | g089h515r806 |
Comments
Comment #0.0
g089h515r806 CreditAttribution: g089h515r806 commentedtypo error fix
Comment #1
g089h515r806 CreditAttribution: g089h515r806 commentedHere is a patch.
Comment #2
g089h515r806 CreditAttribution: g089h515r806 commentedComment #2.0
g089h515r806 CreditAttribution: g089h515r806 commentedAdd more description.