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/Motivation
Because the new default for hook_theme() is now 'template', all 'template' declarations can now be removed.
See #2226207: Make 'template' the default output option for hook_theme()
For example, node_theme() looks like this now:
/**
* Implements hook_theme().
*/
function node_theme() {
return array(
'node' => array(
'render element' => 'elements',
'template' => 'node',
),
…
);
But it could look like this:
/**
* Implements hook_theme().
*/
function node_theme() {
return array(
'node' => array(
'render element' => 'elements',
),
…
);
Proposed resolution
Remove all 'template'
s from hook_theme() declarations.
This can be scripted/bulk search & replaced using a regular expression like this:
\s+'template' => '[a-zA-Z-]+',?
Remaining tasks
- Write patch (novice)
- Review patch to check it fixes the issue, the change is properly documented and for coding standards. Provide test evidence (novice)
- Keep issue summary up to date (novice)
- Ensure that API change is documented in hook_theme()
User interface changes
n/a
API changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#20 | 2246675-interdiff-19.txt | 1.46 KB | rpayanm |
#20 | 2246675-20.patch | 30 KB | rpayanm |
#17 | 2246675-17.patch | 30.64 KB | rpayanm |
#5 | remove-template-from-hook-2246675-5.patch | 4.08 KB | johnstorey |
#3 | remove-template-from-hook-2246675-3.patch | 5.46 KB | holly.ross.drupal |
Comments
Comment #1
mgbellaire CreditAttribution: mgbellaire commentedComment #2
star-szrTweaking the issue summary a bit, thank you for starting this @mgbellaire :D
Comment #3
holly.ross.drupal CreditAttribution: holly.ross.drupal commentedRemoved all references to
'template' =>
in hook_theme() declarations.Unsure if the reference to "template" on line 615 (and several others) is still relevant and need to be removed as well.
Comment #5
johnstorey CreditAttribution: johnstorey commentedRe-rolled patch. Apparently since @holly.ross.drupal rolled the original one, two 'variables' declarations were removed, thus breaking the patch. The two declarations were:
- Around line 2594, in the 'maintenance_page' array
- Around line 2598, in the 'install_page' array
Once the patch was adjusted for this it applied cleanly on my local system.
Comment #6
dcam CreditAttribution: dcam commentedSending this to the Testbot.
Comment #8
star-szrI think it probably makes sense to keep this postponed until #2226207: Make 'template' the default output option for hook_theme() is committed. It is scriptable. Thanks for the efforts @holly.ross.drupal and @johnstorey but it won't pass testing until we get the other issue in and we will just have to keep rerolling it. Trying to save time :)
Comment #11
star-szr#8 still applies.
Comment #12
star-szrAdding a potential regular expression to the issue summary.
Comment #13
star-szrBetter.
Comment #14
star-szrUpdating the regular expression slightly.
Comment #15
star-szrScratch that, those ones are special cases anyway. Carry on :)
Comment #16
star-szrLet's do this, #2226207: Make 'template' the default output option for hook_theme() is in!
My suggestion is that a patch can be crafted here based on #2226207-149: Make 'template' the default output option for hook_theme(), but removing the changes that were committed in #2226207-182: Make 'template' the default output option for hook_theme().
git apply -R
(reverse) might be helpful.Or we can just re-script it.
Comment #17
rpayanmTrying...
Comment #19
star-szrThanks @rpayanm!
These ones need to stay for now because they use underscores. The config_translation one it would be nice to open a small follow-up issue to rename that template but let's keep this focussed.
Extra blank line here ;)
Comment #20
rpayanm@Cottser thank you for review my code ;)
Here the patch :)
Comment #21
star-szrThat looks very shippable to me.
Before patch:
After patch:
The only remaining 'template' lines I could find after patching all had underscores or periods in them.
Comment #22
star-szrUpdating RegEx in issue summary, we can't remove template names that contain underscores.
Comment #23
star-szrComment #24
joelpittetNice diff stats!
Comment #25
webchickYay. :)
Committed and pushed to 8.0.x. Thanks!