Hi,
While working with the Drupal's theme layer to have a better support of different theme engines in our beloved Drupal 7, Pounard discovered that Drupal's templates must have two dots in their names.
The explanation:
A theme engine may only use a 2-part extension (eg. ".tpl.php" or ".html.twig") but cannot use a single part extension (such as ".phtml" or ".twig"). No one ever saw that comming, because almost no one actually write theme engines, but in the end, this as another side effect: you cannot name your templates "some.thing" (for exemple, that would tie to the "some_thing" theme hook).
I suggest you to read the full explanation and its very interesting side effects.
As we cannot mix issue on Drupal.org, we will provide a patch for this issue only.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2826661-21-TESTS-ONLY.patch | 8.86 KB | David_Rothstein |
| #31 | single-filename-extension-do-not-test.patch | 1.69 KB | David_Rothstein |
| #21 | 2826661-21.patch | 13.01 KB | pounard |
| #18 | 2826661-18.patch | 13.49 KB | pounard |
Comments
Comment #2
polHere's the patch.
This patch address only this issue.
Comment #3
polSorry, the previous patch did not include the newly created files.
Here's the same patch with the previously forgotten files.
Comment #6
pounardEither you remove the 'pattern' test, or you include the nyan cat theme engine to this patch, but as I wrote them one cannot live without the other.
Comment #7
polI will remove the pattern test from here and add it in #2825396: Enable modules to define theme engines.
You're ok with that ?
Comment #8
pounardSeems fair enough.
Comment #9
polI already did it in the patch actually.
If you look closely, I moved the file and function that were in the Nyan Cat engine based theme in test_subtheme, already included in the tests.
Comment #11
pounardIt's very weird, lots of errors seems unrelated. Did you test the patch locally?
Comment #12
polHi Pounard,
Tests are still running locally... It take ages!
In the meantime I've uploaded the patch, but I still don't get why it fails... investigating.
Comment #13
pounardJust run the "theme" group, it is quick, if it works, then it's probably unrelated. It does not have any possible side effects outside of theming, so if the "group" test passes, it should pass globally.
Comment #14
polHere's the updated patch. A file was missing, my bad.
Comment #15
polNew patch, removing a function related to the Nyan Cat test theme engine. It will be added by the patch in #2825396: Enable modules to define theme engines.
Comment #16
pounardVery nice, it is still missing one test case: right now we are testing with a pattern that is completely different from the theme hook name, hence the
#theme => ['first_once', 'second_one']which is actually an edge case (even more a side effect of the current algorithm) test, I'm going to add a more "normal" use case where the pattern starts with the theme hook name, which actually would be the real life use case.Comment #17
pounardIn the meantime, the actual patch is RTBC.
If anyone does asks, the line that replaces the strtr() call using preg_quote() was actually not necessary, it just seemed more natural and safer to do this. The original strtr() would allow patterns to use special preg escade characters but in the end, I'm not sure this would be a good thing. In the end I'm even not sure keeping the 'pattern' feature is a good thing.
Comment #18
pounardI renamed test templates names to have a logical suite. Also added more boundary tests, to make it more robust. Only tests are altered theme.inc code remains unchanged.
Thank you very much Pol, you have more patience than me and I really appreciate that.
Comment #19
polVery nice tests, that was indeed needed.
Merci aussi pour le travail accompli :)
Comment #20
pounardHum my comment about the theme_hook_suggestion is wrong, it is actually documented, but bugguy, I should fix it.
Comment #21
pounardComments fixed, everything should be good now.
Comment #22
polSeems pixel perfect for me.
Comment #23
rene bakxThis one looks solid to me as well. Would be awesome if this could be committed before the 7.52 window is closed.
Comment #24
stefan.r commentedThe grammar here seems a bit wonky (can be fixed on commit)
Comment #25
pounard@stefan.r since I'm not a native english speaker, please give us something else we can write in there :)
Comment #26
fabianx commentedSo far I checked that this seems to be fixed in Drupal 8 already, so that is good.
Comment #27
pounardFabianx yes I did look in Drupal 8 and had the same conclusion, just forgot to mention it here, sorry.
Comment #28
pounardAbout the preg_quote(), did ever even saw a single project using the 'pattern' feature ? By quoting it might quote preg special chars that users might have voluntarily used (although see this actually working would definitely be the second most mystical thing among the universe after the universe itself).
Comment #29
rajab natshahGood :)
Are we going to have this in Drupal core?
Comment #30
stefan.r commented@RajabNatshah I think so, the patch looks fine. Assigning to David for further review.
Comment #31
David_Rothstein commentedPerhaps I'm missing something, but I was unable to reproduce this bug in Drupal 7.
For example, see the attached patch (
single-filename-extension-do-not-test.patch). Trying that manually and clearing caches, everything with the Seven theme worked fine even though I made it use .php2 as the extension rather than .tpl.php.The tests included in this issue also don't seem to test that bug - not to say they aren't useful tests in general, but when I ran them without the rest of the patch, they still passed. I am attaching a tests-only version of the patch here just to make sure the same thing happens with the testbot.
As for this part:
It definitely looks like a good change, but I think it needs to go in Drupal 8 also.
Comment #32
pounardHum, fun thing, did you test with a git version ? Considering that we applied a series of patch related to theming not so long ago, it might have been fixed along the way. I happened to experience the bug, can't remember the exact circumstances.