Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Follow-up to #2817103: Theme registry doesn't find templates in subfolders for self-defined theme hooks
Problem/Motivation
Noticed $template_candidates uses $info['theme path'] which never shows a different template.
Proposed resolution
Remove candidates
Comment | File | Size | Author |
---|---|---|---|
#6 | 2821420-6.patch | 737 bytes | joelpittet |
#4 | 2821420-1-reroll.patch | 736 bytes | joelpittet |
Comments
Comment #2
joelpittetComment #4
joelpittetLow-level and trivial patch. Rerolled.
Comment #5
lauriiiI spent quite a long time figuring this out, testing multiple different stages of Drupal 8. I can confirm that this is not needed anymore. This was added as part of #342350: Override template files based on template filename as well as hook name but I can confirm that that use case doesn't need this bit of code anymore. There's also tests proving that this use case still works.
I also searched for the reason why this became redundant. It was caused by this issue #2226207: Make 'template' the default output option for hook_theme() where we separated paths from the template names.
Should we use === here?
Comment #6
joelpittetI think we should use
===
, you're right because of those silly edge cases:php -r "var_dump(0 == 'a'); " => TRUE
Thank you for the review
Comment #7
lauriiiThanks for the change. This looks good now!
Comment #8
alexpottCommitted 7294785 and pushed to 8.4.x. Thanks!
Nice - this looks way more robust.
Comment #11
markhalliwellWell, this change certainly snuck its way in...
Here's a change record (which this should have had):
https://www.drupal.org/node/2952033
Comment #12
joelpittet@markcarver, I think you may have misinterpreted the patch.
Before:
[$info['template'], str_replace($info['theme path'] . '/templates/', '', $info['template'])];
in_array()
checks both templates: one as a whole and one without thetheme path + templates
After:
Only
$info['template'] === $template
The rub is that
$info['template']
never has the path in it. So the second check is the same as the first always.Here's a sample of the output of both variables separated by a colon:
I'm going to unpublish your CR for now so people don't get confused. Hope you don't mind, please correct me if I made a mistake though.
Comment #13
markhalliwellIntentional or not, this suddenly "opened up" template discovery to anywhere in the theme when it was previously limited to just the
/templates
directory.I had to adjust the Drupal Bootstrap base theme accordingly.
Comment #14
joelpittetI don't think it did though... how? did you read the explanation on what it does and how this changed nothing from what I can see, maybe I'm not seeing what you are seeing, please explain.
Comment #15
markhalliwellAfter re-evaluating this and what @joelpittet mentioned, I'm not convinced this does what I originally said it did.
The registry still defaults to the
/templates
directory of a theme:http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Core/Theme/Regist...
I think I got confused between
$info['path']
(which is for the template) and$info['theme path']
which is the root directory of the theme (and what drupal_find_theme_templates() was using).I've deleted the change record.