advanced_forum_theme_registry_alter() goes through a lot of crazy array manipulations to convince core that the various styles directories are part of the theme. It works, but I can't help but think it could be simpler. I'm not very good with arrays and there's a very good chance this code could be condensed by someone with more of a clue. So I'm putting this issue out there hoping someone with said clue about arrays will take a look and tell me if it could be made simpler.
For quick reference, here's the code:
// --- The following section manipulates the theme registry so the .tpl files
// --- for the given templates can be found first in the (sub)theme directory
// --- then in ancestor themes, if any, then in the active style directory
// --- for advanced forum or any ancestor styles.
// Affected templates
$templates = array('node',
'comment',
'comment_wrapper',
'forums',
'forum_list',
'forum_topic_list',
'forum_icon',
'forum_submitted',
'author_pane',
'advanced_forum_statistics',
'advanced_forum_search_forum',
'advanced_forum_search_topic',
'advanced_forum_topic_list_view',
'views_view_fields__advanced_forum_search',
'views_view_fields__advanced_forum_search_topic',
'views_view_forum_topic_list__advanced_forum_topic_list',
'views_view__advanced_forum_topic_list',
'views_view__advanced_forum_topic_list',
'advanced_forum_topic_legend',
'advanced_forum_forum_legend',
'advanced_forum_topic_header',
);
// Find all our ancestor themes and put them in an array.
global $theme;
$themes = list_themes();
$ancestor_paths = array();
$ancestor = $theme;
while ($ancestor && isset($themes[$ancestor]->base_theme)) {
array_unshift($ancestor_paths, dirname($themes[$themes[$ancestor]->base_theme]->filename));
$ancestor = $themes[$ancestor]->base_theme;
}
// Get the sequence of styles to look in for templates
$lineage = advanced_forum_style_lineage();
if (!array_key_exists('naked', $lineage)) {
// Add naked in at the end of the line to prevent problems if a style
// doesn't include all needed templates.
$lineage['naked'] = drupal_get_path('module', 'advanced_forum') . '/styles/naked';
}
foreach ($templates as $template) {
// Sanity check in case the template is not being used.
if (!empty($theme_registry[$template])) {
// If there was a path in there, store it.
$existing_path = array_shift($theme_registry[$template]['theme paths']);
// Add paths for our style and ancestors before the existing path, if any.
foreach ($lineage AS $style => $style_path) {
array_unshift($theme_registry[$template]['theme paths'], $existing_path, $style_path);
$existing_path = array_shift($theme_registry[$template]['theme paths']);
}
// If there are any ancestor paths (ie: we are in a subtheme, add those)
foreach ($ancestor_paths as $ancestor_path) {
$theme_registry[$template]['theme paths'][] = $ancestor_path;
}
// Put the active theme's path last since that takes precidence.
$theme_registry[$template]['theme paths'][] = advanced_forum_path_to_theme();
}
}
Comments
Comment #1
michelle