To reproduce:
Define a path (through hook_menu or another module (eg views)) with a hyphen.
Eg
/**
* Implements hook_menu
*/
function mymodule_menu() {
$items['my-node'] = array(
'page callback' => 'node_page_default',
'access arguments' => array('access content'),
// Required to make 'node/add' appear on the top-level of 'navigation' menu.
'menu_name' => '',
'type' => MENU_CALLBACK,
);
return $items;
}
*Make the following page template in your theme
page--my-node.tpl.php
*Flush your caches
*The new template is not used because:
**The theme registry auto-discovery mechanism replaces all hyphens in the templates it finds with underscores - so in this case the theme_registry has a hook for page__my_node
**but theme_get_suggestions does not do the same thing in reverse so if the args come in as my-node, the theme_hook_suggestions array contains page__my-node - for which there is no matching theme hook
This patch changes theme_get_suggestions to replace hyphens with underscores so that the suggestions returned match the hooks registered and hence the template is used.
Comments
Comment #1
larowlanHere is the patch
Comment #2
larowlanReroll against RC2
Comment #3
larowlanAttached is
a) a module for testing this, it defines a path my-module/node which is just the default /node callback
b) a page template for this path (page--my-module--node.tpl.php) which goes in your active theme folder
To reproduce
1) Copy the module to the appropriate place
2) Copy the page tpl to your theme folder and remove the .txt extension
3) Enable the module
4) Flush your cache (to be sure)
5) Visit /my-module/node
Without the patch - you notice no difference - the new template is not recognised.
With the patch - you get 'THIS IS THE ALTERNATE PAGE TEMPLATE' in large letters at the top of the page
Comment #4
realityloopTested both with and without patch and confirmed working with #2 patch
Comment #5
Dries CreditAttribution: Dries commentedThis comment reads as if we're doing something dumb. First we convert - to _, then we convert _ to -. It sounds like we want to be more articulate.
Comment #6
larowlanHere it is again with revised comments
Comment #7
larowlanComment #8
realityloopUpdated comment is easier to read.
Comment #9
realityloopBumping version so it doesn't get missed
Comment #10
webchickWell, that's some commenting! :)
I made a couple of small formatting adjustments (moved note about hyphen/underscore to previous line, removed the link to this issue since we don't do that really, added a period, and Americanized the word "recognized") and...
Committed #6 (with modifications) to HEAD.
It'd be nice if it's possible to have a testcase for this. Seems like we ought to be able to. So marking down to "needs work" for that.
Comment #11
mdupontIt looks like issues with hyphens and template suggestions aren't limited to pages... See #1021270: Blocks for custom menus are impossible to theme for such a bug with the blocks created by menu.module. No custom menu block can use specific templates.
Comment #12
larowlanHere's a patch for review
Comment #13
larowlansorry, wrong issue :-(
Comment #14
pixeliteJust to clarify comment 13... larowlan meant to post his patch in comment 12 to #1021270
Comment #15
larowlanHere's a patch that adds a test case.
Thanks wojtha for pointing me in the right direction for this.
Updating to D8 for fixing there first.
Tagging to add 'needs backport'.
Comment #17
larowlanHmm passes locally against D7 master, time to get a D8 environment up and going
Comment #18
realityloopnot sure why.. but #6 already appears to be committed to D8
Comment #19
larowlanYes, #6 made it into 7.0
Comment #20
larowlanHmm passes on local D8 install too, trying again in case something dodgy with the previous patch
Comment #22
larowlanAdding more debug to tests
Comment #24
larowlanMore test debugging in this patch
Comment #26
larowlanOk, so testbot test is failing because drupal_is_front_page evaluates true for the test bot, not for local simpletest.
Will add additional logic to the test.
Comment #27
larowlanHopefully this one is the last (apologies to all those who've subscribed via email to this thread).
Comment #28
clemens.tolboomWhy is this 'space' layout-ed?
Is this a bug of our testbot?
Our should you navigate to the right context somehow?
Powered by Dreditor.
Comment #29
larowlanWill add a hook_menu definition with the hyphen path and then navigate to that path before running the test.
Should be able to use the arg function then.
Thanks for the review
Comment #30
larowlanOk, moved logic to theme.test where similar tests were being performed.
Cleaned up comments.
Comment #31
dcrocks CreditAttribution: dcrocks commentedThere are 3 other related issues with similar patches:
http://drupal.org/node/1021270
http://drupal.org/node/1129972
http://drupal.org/node/1076132
And shouldn't this issue be under the block module component?
Comment #33
larowlandcrocks, this issue concerns page templates, not blocks, see #1021270: Blocks for custom menus are impossible to theme for the block issue.
For what it's worth the patch for this issue made it into Drupal 7.0, we are just working on tests now.
Comment #34
larowlan#30: HyphenPathsAndThemeHookSuggestions-992376-30.patch queued for re-testing.
Comment #35
dcrocks CreditAttribution: dcrocks commentedSorry, patch in #12 confused me.
Comment #36
404 CreditAttribution: 404 commentedsubscribe
Comment #37
larowlanFor some reason the patch at 30 failed the first bot test, but passed the second one - reattaching here to clear up all confusion
Comment #38
realityloopPassed locally too:
Pass Other theme.test 49
Found expected page suggestions for paths containing hyphens.
Comment #39
webchickAwesome! Thanks a lot for the tests!
Committed to 8.x and 7.x!
Comment #40
clemens.tolboomDo we 'needs backport to D7' still? #39 displays -needs backport to D7 _AND_ +needs backport to D7 ?!?
According to http://drupalcode.org/project/drupal.git/commit/e85b057 this is committed to D7
Do we have a tags workflow guide somewhere?
Comment #41
webchickI like leaving the tag there so I can go back and see what I've fixed.
I have no idea why it's resetting the tags randomly though. Must be some bug in comment_alter_taxonomy.