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.
Problem:
The theme registry names theme hooks with underscores, because that is what PHP will allow in a function name. But in creating template files for Drupal, we've been using dashes. We accomplish this with the core template by setting the 'file' in the registry hook to the proper name. Discovery, however, keys on the name of the hook, which contains underscores.
This patch modifies the discovery to convert underscores to dashes when discovering templates in the file system. ALL underscores will be converted.
I haven't had the time to test this yet.
Comment | File | Size | Author |
---|---|---|---|
#8 | dynamic_text.tar_.gz__1.txt | 10 KB | merlinofchaos |
#7 | template-underscores_5.patch | 1.74 KB | merlinofchaos |
#5 | template-underscores_4.patch | 1.43 KB | dvessel |
#1 | template-underscores_3.patch | 1.41 KB | merlinofchaos |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedHere's the patch
Comment #2
dvessel CreditAttribution: dvessel commentedThe patch had no effect. Tried with the new .tpl files. anything with an underscore registers. Dashes don't show up at all. Same as before.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedCrapzor!
Comment #4
dvessel CreditAttribution: dvessel commentedComment #5
dvessel CreditAttribution: dvessel commentedHere's a patch. Was due to how the variables were used.
Comment #6
dvessel CreditAttribution: dvessel commentedTo test this patch, place a template file from one of the modules directory into your theme. Make some small change so you know it's picking up the new file then rebuild the theme registry.
for example. copy modules/user/user-profile.tpl.php into garland. Reset the cache with
drupal_rebuild_theme_registry();
by placing it inside template.php and observe.Does it show your changes at example.com/user/1 ?
Comment #7
merlinofchaos CreditAttribution: merlinofchaos commentedThis patch wasn't properly translating patterns. This one should do that. Will provide test material in a followup.
Comment #8
merlinofchaos CreditAttribution: merlinofchaos commentedThis test includes a module and a theme; it's designed for testing the dynamic theme stuff. The theme contains overrides for a and c in the template, and d as a .tpl.php -- anything other than those should revert to the default.
The module contains the theme and a test page.
Comment #9
dvessel CreditAttribution: dvessel commentedThanks for the test files. It works now.
Comment #10
Gábor HojtsyLast thing to check before this gets committed is where does $info[pattern] come from and what could it contain?
I mean, the underscore has no special meaning in preg expressions, but the dash can have special meaning, if used to define ranges (ie. [a_z] becomes [a-z] after the replacement, which modifies the meaning.
Although this sounds like a possibly minor problem, it would be nice to rule it out by knowing more about the pattern. Otherwise the patch looks sane to me.
Comment #11
merlinofchaos CreditAttribution: merlinofchaos commentedThe pattern is set by hook_theme(). In general, I don't expect it to be a complex regex; the standard I've introduced (and documented) is to set patterns like this: 'views__' -- the only reason it's a regex, honestly, is in case developers want additional flexibility.
Since the possible characters in a function name is really narrow, i.e, alphanumeric plus underscore, it seems unlikely that we'll see ranges. I do understand your concern, though; I'm not sure how easily we can actually distinguish real dashes from dashes in a range. Perhaps that requires a regex. Ahh, the irony. Maybe I'll put a regex expert on this to cover that possibility.
Comment #12
merlinofchaos CreditAttribution: merlinofchaos commentedThe more I think on it, the less likely that scenario seems, Goba; [ isn't a valid character in a function name, so it seems unlikely that we'll see some odd use of _ where translating into a - will break the pattern.
Comment #13
Gábor HojtsyWell, [] is only used to define the range and will not end up required in the string which it is matched with, it is just part of the range syntax. Anyway, I understand that this is a very small nitpick, and could agree that we will not meet this kind of misbehavior.
So: committed!
Comment #14
(not verified) CreditAttribution: commented