it do not work when that's following pattern,
theme_hook_suggestions:
$variables['theme_hook_suggestions'][] = name-name__name / name_name__name / name__name-name
tpl:
name-name--name ....etc..
following may not work:
[poll.module at line 772, column 17] $variables['theme_hook_suggestions'][] = 'poll_vote__block';
[poll.module at line 875, column 17] $variables['theme_hook_suggestions'][] = 'poll_results__block';
[poll.module at line 890, column 17] $variables['theme_hook_suggestions'][] = 'poll_bar__block';
[profile.module at line 593, column 17] $variables['theme_hook_suggestions'][] = 'profile_wrapper__' . $field;
[search.pages.inc at line 79, column 15] $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['type'];
[search.pages.inc at line 114, column 15] $variables['theme_hook_suggestions'][] = 'search_result__' . $variables['type'];
[taxonomy.module at line 648, column 15] $variables['theme_hook_suggestions'][] = 'taxonomy-term__' . $vocabulary_name_css;
[taxonomy.module at line 649, column 15] $variables['theme_hook_suggestions'][] = 'taxonomy-term__' . $term->tid;
[theme.inc at line 2466, column 15] $variables['theme_hook_suggestions'][] = 'region__' . $region;
also, I think we should patch it
function template_preprocess_region(&$variables) {
// Create the $content variable that templates expect.
$variables['content'] = $variables['elements']['#children'];
$variables['region'] = $variables['elements']['#region'];
$region = drupal_region_class($variables['region']);
$variables['classes_array'][] = $region;
$variables['theme_hook_suggestions'][] = 'region__' . $region; // region__region-sidebar-first
}
to
function template_preprocess_region(&$variables) {
// Create the $content variable that templates expect.
$variables['content'] = $variables['elements']['#children'];
$variables['region'] = $variables['elements']['#region'];
$region = $variables['region']);
$variables['classes_array'][] = drupal_region_class($region);
$variables['theme_hook_suggestions'][] = 'region__' . $region; // region__sidebar_first
}
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | region.overrides.patch | 1.96 KB | Anonymous (not verified) |
| #9 | taxonomy_term.patch | 1.26 KB | droplet |
| #9 | region.patch | 829 bytes | droplet |
Comments
Comment #1
Anonymous (not verified) commentedcan you elaborate on what you mean by 'it do not work'? modules can't override core?
Comment #2
droplet commentedYes. We cannot overriding themes when using above theme_hook_suggestions pattern.
theme_hook_suggestions now only work with :
$variables['theme_hook_suggestions'][] = name__name_name / name__name__name / name__name__name_name
Comment #3
Anonymous (not verified) commentedok, can you help us write a test case that fails? say one that creates a test module that tries to override a theme template but fails?
that will help a lot with making a patch to fix this.
Comment #4
droplet commentedsure if I can but do not how to write it against drupal QA.
I make a mistake above. name_name__name is works.
so any pattern with "-" and like this poll_results__block_block is not working.
Comment #5
effulgentsia commentedtemplate_preprocess_region() is indeed broken. Values for 'theme_hook_suggestions' need to contain underscores, not hyphens. So the pattern is that $variables['theme_hook_suggestions'][] needs to be set to something like 'region__sidebar_first'. This will allow a theme to implement a 'region--sidebar-first.tpl.php' file, but the underscore to hyphen conversions happens only when converting a suggestion to a template file name. Passing the output of drupal_html_class() to a 'theme_hook_suggestions' assignment is a bug, and makes the suggestion not work, so region-specific template files aren't being used.
Writing a patch to fix the bug in template_preprocess_region() is easy. Adding a test to that patch to make sure a theme's "region--sidebar-first.tpl.php" file gets used is a little harder, but do-able. Anyone up for trying it?
Comment #6
effulgentsia commented.
Comment #7
effulgentsia commentedNot critical, but definitely is a bug worth fixing.
Comment #8
droplet commentedOK. 2 quick patches.
something like 'name__name_name' require fixing from API side.
Comment #9
droplet commentedComment #10
Anonymous (not verified) commenteddroplet, thanks for the patches! have a look at this link to see the best way to create them for drupal: http://drupal.org/patch
i've rerolled them into a single patch, and changed the status to 'needs review' so the testbot will pick it up.
Comment #11
effulgentsia commentedPatch looks great. Thanks! I'm RTBC'ing it in case Dries or webchick are willing to commit this without tests. Tests are needed, but honestly, lots of things in the theme system are still missing adequate test coverage, so perhaps, they'd be willing to let theme system test coverage be handled in separate issues.
Comment #12
marcingy commentedChanging to major as per tag.
Comment #13
mustanggb commentedTag update
Comment #14
dries commented#10: region.overrides.patch queued for re-testing.
Comment #16
bojanz commented#11 was actually committed (wanted to do a reroll and saw the changes already there).
Comment #17
effulgentsia commentedStill needs tests though.
Comment #18
effulgentsia commentedAdding tests is always worthwhile, but not "major".
Comment #19
effulgentsia commentedAck. Sorry for taking 3 comments to update all the issue fields.
Comment #20
droplet commentedrecall my memory,
my patch only fixed "name__name_name",
patterns like "poll_results__block_block" not solve yet.
I can't roll out a patch until get some more info. So what name patterns we can use, anyone could confirm it ?
Thanks.
Comment #21
effulgentsia commentedThanks, @droplet. Please see #5. $variables['theme_hook_suggestions'] should only ever contain "machine names" (i.e., lowercase letters, numbers, underscores). It should never contain hyphens. Underscore to hyphen conversion happens only when translating a theme hook suggestion to a template file name, but theme hooks are indexed in the theme registry by machine name, so hyphens in theme_hook_suggestions are always wrong.
Comment #22
effulgentsia commentedBy the way, I don't see poll_results__block_block anywhere in HEAD, but if it were there, it wouldn't be wrong per se, just perhaps a poor name choice simply because it wouldn't be clear what purpose the 2nd 'block' serves. poll_results__block is fine and makes sense (i.e., a variant of poll_results, specific to when viewed in a block). Wherever you see the double underscore, it means the thing is a variant of whatever comes before the double underscore, and in a few cases, you can even find multiple double underscores, like
'field__' . $element['#field_name'] . '__' . $element['#bundle'], which allows for a bundle-specific variant of'field__' . $element['#field_name'], which itself is a field-specific variant of 'field'.Comment #23
droplet commentedIm confused.
if I set that to follow should work well in expectation ??
$variables['theme_hook_suggestions'][] = 'region_sth__' . $variables['region'];print_r($theme_hook_suggestions);
Array ( [0] => region_sth__sidebar_first )However, I use "region-sth--sidebar-first.tpl.php" to test and FAILED
so is it the bug, right ??
./modules/taxonomy/taxonomy.module: $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->vocabulary_machine_name;
./modules/taxonomy/taxonomy.module: $variables['theme_hook_suggestions'][] = 'taxonomy_term__' . $term->tid;
./modules/poll/poll.module: $variables['theme_hook_suggestions'][] = 'poll_vote__block';
./modules/poll/poll.module: $variables['theme_hook_suggestions'][] = 'poll_results__block';
./modules/poll/poll.module: $variables['theme_hook_suggestions'][] = 'poll_bar__block';
./modules/search/search.pages.inc: $variables['theme_hook_suggestions'][] = 'search_results__' . $variables['module'];
./modules/search/search.pages.inc: $variables['theme_hook_suggestions'][] = 'search_result__' . $variables['module'];
...
..
Comment #24
effulgentsia commentedAh, this might help answer the confusion. The double-underscore is there to delimit a more specific version of a "base" theme hook. So, for example, "node__article" is a more specific version of the "node" theme hook, and therefore, "node--article.tpl.php", if it's there, gets used as the template file instead of "node.tpl.php" for article nodes.
'region_sth__' . $variables['region']would make sense if there was a base theme hook of 'region_sth'. You could create a module that implements hook_theme() to define a 'region_sth' theme hook, but without that base theme hook being defined, 'region-sth--*.tpl.php' files don't get found by the theme system.Note that 'taxonomy_term', 'poll_vote', 'poll_results', 'poll_bar', and 'search_results' are all examples of theme hooks defined by some module's hook_theme() implementation, so double-underscore after any of these makes sense. In fact it is precisely, because base theme hooks can and often do consist of more than one word, that in D7, we started using "__" as the "suggestion" delimiter to avoid name conflicts with "_" as merely a word delimiter. As an example, 'block-admin-display-form.tpl.php' is its own base template file for theming the admin/structure/block table, whereas, if you had a module called 'admin_display_form.module', then a theme could have a 'block--admin-display-form.tpl.php' to override block.tpl.php for those module's blocks only, and this template file name wouldn't conflict with 'block-admin-display-form.tpl.php'.
Comment #25
droplet commentedthanks effulgentsia, your reply is very helpful. I learn lots stuff from this issue :). thanks again.
Comment #26
_________ commentedJust found this thread in the bug system ...
I'm having problems with some (related to this?) region-specific overrides working, and others not. I'll just mention the bug post here: http://drupal.org/node/1200498, which references my initial forum chat.