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.
When you are using a different theme engine than php-template in your sub theme that extends a base theme that uses php-template, the system module copies the engine and owner of the base theme over in the child theme. This results in the child theme not using the engine defined in the .info file.
For example, I created a subtheme called mothertwig which extends mothership
name = Mothership
description = The Motheship is a basetheme for cleaning up crufty markup
screenshot = screenshot.png
engine = phptemplate
core = 7.x
php = 5.2
name = mothertwig
description = TWIGalized version of the mother
screenshot = screenshot.png
engine = twig
core = 7.x
php = 5.2
base theme = mothership
The result was that if you did a var_dump of list_themes()—both themes where assigned to php-template.
Possible work around for sub-themes using Twig for D7
Add the following to the template.php
(7.x) file:
/**
* Implements hook_system_info_alter().
*/
function mothertwig_system_info_alter(&$info, $file, $type) {
if ($type == 'theme' && module_exists('tfd7') && ($info['name'] === 'mothership' || $info['base theme'] === 'mothership')) {
$info['engine'] = 'twig';
}
}
Comment | File | Size | Author |
---|---|---|---|
#164 | interdiff.txt | 675 bytes | simon.mellerin |
#164 | 1545964-164-theme_engine_inheritance.patch | 26.21 KB | simon.mellerin |
#149 | 1545964-149-theme_engine_inheritance.patch | 25.16 KB | pounard |
#102 | 1545964-102-theme_engine_inheritance-FULL.patch | 19.02 KB | pounard |
#96 | 1545964-96.patch | 16.14 KB | Pol |
Comments
Comment #1
Rene BakxThe attached patch fixes this issue by adding an extra condition that checks if the base engine matches the child engine.
Comment #2
Rene BakxLet me try that again. (must learn to read manuals before being excited about delivering a patch first)
Comment #3
tim.plunkettThis is not a critical bug, and it may not be major either.
I don't believe you should be able to subtheme with a different theme engine. This might be won't fix.
Also, there is a minor indentation issue.
Comment #4
Rene Bakxi do not agree so i'am settings this back to D7 instead of D8. It is one extra if that can save a lot of time to themers. Instead of having to duplicate a truckload of code and settings between two themes just becaiuse they have a different output engine.
Having the option to extend a php-template base theme in a different engine is rather essential for the acceptence of non php-template engines amongst themers. That is something I learned last week at FrontendUnited while explaining and discussing the advantages of using twig as a template system.
Comment #5
catchThis hasn't changed in Drupal 8 vs. Drupal 7, so it needs to be fixed in 8.x first, see http://drupal.org/node/767608 for why.
Looks like a very small change, but I agree with Tim Plunkett it needs a test so it doesn't regress in the future.
It should be possible to work around this bug with a very small module implementing hook_system_info_alter(), and it's not sufficiently severe to be considered major - see http://drupal.org/node/45111 for the categorization.
Comment #6
Rene BakxI tried that system info hook to, but the problem was that the damage was already done when that hook
is executed. Changing it on the hook level implies that I need to rebuild the entire tree of themes available just to reset two
flags back in the original state. This causes a lot of duplicated code and non needed overhead compared to the patch suggested.
But perhaps you can explain me how to get this tested, as this bug prevents most themers to actually play with, in my case Twig in D7. I can add this patch to the drush make file for the installation profile i wrote if that would speed to
process? Because as far as I could test yesterday with extending both mothership and omega with a twig based theme this little if worked like a charm.
To me it was major because it renders the child theme feature rather useless.
Comment #7
catchThis should be close to what's needed for testing:
- create a new test theme that inherits from another theme in core but specifies a different theme engine. We already have test themes in core, it might even be possible to just add the different theme engine line to one of them, or copy it to a new theme and change that one line, removing any extraneous stuff.
- write an automated test that checks the theme engine is correct in system info.
The test should fail without the patch, but pass with it.
Comment #8
Rene Bakxsomething like this you mean?
because that works if i create a second theme that inherent the test_theme if I add the extra theme in the theme_test.module.
The only problem seems to be, that the test-suite isn't looping trough the bootstrap in the same way a normal request would because no external engines are loaded and therefor the twig_init() is never called, which results that the template.php of a twig theme is also never loaded.
Of course I could expand the test in forcing the engine to be included in some way, but that would be as useful as hardcoding every test not to fail. I feel a little lost here, cause theme engines are somewhat of a second class citizen in Drupal 7. I know for a fact that my patch works. But if the above test is to 'simple' to be a true test, I have no clue what so ever how to make a more compiling test to convince the rest of the world that my patch get's the job done.
Comment #9
Rene BakxComment #10
tim.plunkettMissing an updated patch.
Comment #11
Rene Bakxthe update patch above is still valid?
Comment #12
tim.plunkett#2: fix_theme_inheritance_1545964.patch queued for re-testing.
Comment #14
Rene Bakxah, i guess this patch needs to be rewriten against the current state of d8, however that seems a bit useless to me. The patch was created to allow twig themes extend a phptemplate in D7. D8 currently comes with twig ;)
Comment #15
tim.plunkettD8 still ships with phptemplate, and it isn't being removed any time soon.
Comment #16
Rene BakxNot sure if this is fixed with D8 and Twig in core now, but the problem still excists for D7 installations. How to proceed?
Comment #17
johnvsc CreditAttribution: johnvsc commentedWas this ever backported to Drupal 7?
Comment #18
pzula CreditAttribution: pzula commentedBased on how close the Twig initiative is to being complete, I am postponing this to be revisited before release. Please see: http://drupal.org/node/1987510
Also, bother xjm if you don't agree ;)
Comment #19
catchThis shouldn't have been postponed on twig, don't think it's got anything to do with that.
Comment #20
Kars-T CreditAttribution: Kars-T commentedWe would love to switch to twig as easy as it could be in D7 and it doesn't seem to be possible with out this feature.
In D8 as far as I understand it currently all themes are now objects and I can't really find inheritance beyond the check in getActiveTheme() Line 237. So I believe that this doesn't really apply to D8 anymore because everything is handled in an independent object and if no engine is found the current engine will probably call to the engine of the base theme object?
For D7 I updated the patch to current core as a first step. Don't know if all keys should be checked seperatetly or should still be in one if().
Comment #21
Kars-T CreditAttribution: Kars-T commentedSorry that was the another patch... readding file.
Comment #22
Kars-T CreditAttribution: Kars-T commentedUpdating status. Maybe this doesn't need "needs backport" anymore as we got Twig in D8 and only D7 needs this feature?
Comment #24
Rene BakxThat is correct, only D7 has this issue. A backport is even impossible, because of structural changes in the theme system between D7 and D8.
Comment #25
Kars-T CreditAttribution: Kars-T as a volunteer and at intosite GmbH commentedThan lets change the version to D7 and reroll the patch.
Comment #27
cilefen CreditAttribution: cilefen commentedComment #28
Rene BakxI will test this later next month, kinda busy @work right now. But it would be awesome if we can get this patch in the next D7 release :)
Comment #29
markhalliwellThis needs to be fixed or verified that the bug doesn't exist in 8.x first before anything happens in 7.x.
Added an example to the issue summary on how to "fix" base/sub-themes temporarily that use Twig for D7.
Comment #30
OnkelTem CreditAttribution: OnkelTem commentedSo important issue and so long and unsuccessful storyline. It reminds me another issue where you couldn't host Drupal in environments secured with ACL.
Ok, not prob, adding one more duck tape patches to my local Drupal 7 core is a matter of moments.
Thanks for the patch and for your patience @Rene Bakx.
Comment #31
madhavvyas CreditAttribution: madhavvyas as a volunteer and at CIGNEX commentedProvided Patch is already updated with latest Drupal 7 branch. I have verified with origin/7.x, it applied successfully.
Comment #32
pounardHere is a proper patch, inheritance is broken on multiple places, and theme() function itself considers a global $theme_engine and uses it for all templates.
This patch a bit more complex gets rid completely of the global $theme_engine variable, enforce drupal_find_theme_templates() function to lookup for the current theme being scanned and set its engine into the stored theme hook information, then the theme() function can fallback on the $info['engine'] information instead of trying to use a single hardcoded global variable.
The reason why this is necessary is because if you have, for example, theme A (phptemplate) and theme B (twig) which uses theme A as base them, it may happen any of these two scenarios:
Comment #33
pounardPer #1537050: [meta] Should we keep / improve multiple theme engine functionality? I guess this won't ever make it to Drupal 8.
Comment #35
pounardAnd there is still an issue with the patch, core is unable to find the right theme engine to use for modules templates when you provide them with another format than .tpl.php, but that's a real problem because:
So the solution is probably to attempt to lookup for a "theme engine" key in the module info file.
Comment #36
pounardI'm sorry, I used the [] array syntax at once place, force of habbits...
Comment #38
pounardAnother patch, hope it helps:
Comment #39
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedRTBC - Looks great to me.
Comment #40
rcaracaus CreditAttribution: rcaracaus as a volunteer commentedIt would be awesome to get this merged. I tested it using a few different page, node and view templates and works well. I seemed to have an issue using hook_theme within my theme (or a custom module for that matter) then overriding in my sub-theme, but could have been something else unrelated to this patch.
I have a few legacy Drupal 7 sites that copy paste a TON of code from a twig styleguide into different templates. When updates are made to the components I need to sift through different template files and make sure the markup gets updated, this patch would allow some of these components to be living. I am not sure how stable TFD7 is to run on a production site, but what this patch would let me do is create a sub-theme and one by one extend some components from twig, while keeping my legacy components in phptemplate.
Comment #41
pounardIt took me a few hours of debug to make this patch right, and I'd love to see it merged too! Actually, we do use TDF7 on many production sites, no problems so far, but on some other projects we tend to use a custom Twig engine with a partial Symfony 3 embeded into Drupal 7, and it's working very nicely, see https://github.com/makinacorpus/drupal-sf-dic/blob/master/Resources/engi...
Comment #42
rcaracaus CreditAttribution: rcaracaus as a volunteer commented@pounard - is there any way to do this without patching core?
Comment #43
pounardNot really, there are probable a few hacks you can do to make it work (the original tdf7 engine does a few) but it does not solve entirely the problem. Patching core is the only way to make this work as designed imho.
Comment #44
Rene BakxFabian gained committing powers for Drupal 7 if i'am right, so my best guess is that he is the one that could get it committed to core ;)
Comment #45
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#44: That is correct.
Unfortunately I missed 2 things in my RTBC-review:
--
Indentation change?
--
Also this definitely needs tests.
The theme registry is very complicated and adding more untested functionality is not a good thing.
I especially would want the tests to ensure that future changes won't break this again for tdf7.
Comment #46
Rene BakxTesting is indeed a very good point, yet I must admit I have no clue where to start this test. I think one way is to create a few mock arrays simulating the theme.info.
1. Normal php-template based theme.info
2. Normal other engine based theme.info
3. PHP template main theme, with other engine subtheme.
Not sure if the other way around is also something that could happen, and needs to be tested?
Edit :
Wondering how the test would pass on D.O, we can test with the above mentioned mock array, but the real theme engine and theme loading part will always fail because obviously TFD7 is not a part of core and requires a non drupal lib (Twig itself) and a Twig based theme,
Comment #47
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#46:
I suggest to port the nyan cat twig engine from D8, which is tests only. (core/tests/engines/nyan)
Then do the exact same setup like you did with mothership and mothertwig.
E.g. have a base theme use phptemplate and the child theme use nyan engine.
So what I would like to see is a true integration test and not just 'mocks'.
Comment #48
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedWhy was this issue moved back from Drupal 8 to Drupal 7 without fixing it in Drupal 8?
Unless I'm missing something, Drupal 8 supports multiple theme engines also. Are we sure the bug doesn't exist there?
Comment #49
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#48: I am pretty sure we need to fix in in Drupal 8 also. I had left it originally at Drupal 7 as that might be easier to work with, but yes it needs to be fixed in Drupal 8 first - using the nyan cat engine.
Comment #50
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #51
pounardSeriously... Don't mean to be rude, but patch is actually working and ready (even thought you'd like more tests, there is already all the actual tests passing); please, please, don't block this for Drupal 8.
Comment #52
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#51: I am pretty sure once we have a working patch for D7 with tests, this can be ported quickly to D8 as the code was almost not touched at all.
So I am happy to continue for 7.x for now, but we need a test.
Comment #53
Rene BakxBut to create that test, does that mean the nyan cat needs to be ported to D7 first? Or can that engine be a part of the test itself?
Porting an engine for the sake of test sound a bit contra productive to me, because it would imply that the port of the engine needs tests as well before the engine can be committed to D7 or D7 test repository. Sounds like an awful amount of test inception work just for this rather simple patch.
Comment #54
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#53: Nyan cat can be part of the patch to create the test.
It is a very simple engine and the test for it is minimal.
The D8 code is also almost D7, so a port is just copying it over I guess and it can happen in this issue.
Comment #55
pounardI do agree with @Rene Bakx, extreme complexity seems out of scope, porting a D8 theme engine is not that trivial.
Comment #56
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedhttp://cgit.drupalcode.org/drupal/tree/core/modules/system/tests/themes/... is the code.
The .info can be used from twig for d7. And the test theme is here:
http://cgit.drupalcode.org/drupal/tree/core/modules/system/tests/themes/...
It should really not be difficult to port this.
Comment #57
pounardOh I should have looked before speaking, I guess it's simple enough, but are you sure this covers this patch test cases?
Comment #58
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#57: I am pretty sure it should suffice to be able to define two themes one based on phptemplate and one based on nyan cat and then reproduce the bug in the IS.
Another reason I have for having tests is that while the fix looks straightforward, we want to do as minimal changes as possible in D7, so with the tests in place, we can also see whether there is an easier solution.
And chances are very high that if we have a very good D7 patch that porting it to D8 will be very simple (as most code is the same).
Comment #59
pounardOk, nevertheless, I can't work on this right now, maybe next week but I can't promise anything I'm overloaded in work.
Comment #60
PolI'm also looking forward for this, I need it.
Comment #61
rcaracaus CreditAttribution: rcaracaus as a volunteer commentedYea, would love to see this in
Comment #62
Pol@pounard: any new status on this ?
Comment #63
pounardI don't have time to write those tests at the moment, so it's not moving forward.
Comment #64
PolSee next comment.
Comment #67
PolDeleted.
Comment #68
PolLooks like that last patch prevent seven_preprocess_page() function work. Looking into it.
Comment #70
PolDeleted.
Comment #71
PolI've updated the patch.
When using panels, the admin interface using Seven theme (phptemplate) must be able to load templates from a theme using another theme engine.
In order to do so, the theme engine has to be loaded or else, the following conditions in theme.inc won't never work:
The condition:
has also been removed because it's useless now.
Here's the updated patch.
We are heavily testing this patch on all our development instances. If it's ok we will soon put it in production, as we have now switched to TWIG for theme development.
Comment #73
pounardNeed to update a few in-development sites with your latest patch version, but aside it looks good. Some question though: you are using the list_theme() function to when initing the engines which makes me think that you are initing *all* the theme engines, is that necessary?
Comment #74
PolHi @pounard,
I did this because, when you're using, for example a theme hook that has been defined with another theme engine (current example with Panels layouts and TFD7), Drupal has no way to know which theme is used, so, this is why I initialize all the theme engines.
I took care of not loading them twice as you can see.
Maybe it's not the best option, if you have a better idea let me know, I'm really willing to push this patch forward.
On the other hand, I also think that the conditions:
and
are not needed anymore.
What do you think ?
Thanks.
Comment #75
PolDear @FabianX,
Here's a patch for Drupal 8.2.x.
Let me know if I'm on the right track.
Thanks!
Comment #76
PolHi,
Here's a patch for Drupal 7, including tests.
There's only one test failing, and I'm willing to get help on this one.
I'm not able to reproduce it when I do the step manually on my local instance.
Thanks.
Comment #78
pounardFailed to include theme.inc seems weird, are you sure the patch apply on current 7.x branch?
Comment #79
PolHere's an updated patch for Drupal 7.
While doing the tests, I noticed that it was impossible to have a theme engine in a module.
So I wrote a hook for this. It's mostly based on hook_system_theme_info() but for theme engines.
There's still only one tests failing but I'm unable to find why yet.
I guess it's a matter of time.
Comment #80
PolComment #81
pounardThis looks RTBC to me.
Comment #82
PolIt's not green yet :)
Comment #83
pounardYes, but I do approve the code :) Even though some minor errors could remain, tests will tell.
Comment #85
SebCorbin CreditAttribution: SebCorbin at Makina Corpus commentedLittle typo in template override test
Comment #86
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedCould we move the adding of theme engines via modules to its own issue (including adding nyan cat theme engine).
I do approve of that change (Nice work!), but it should live in its own issue.
Also the D8 coverage (nice work in proving that D8 is not affected should not go to waste and live in a new child issue, normal task).
Plan of attack:
Child issues for:
- a) D8 test coverage (now that you have written it it would be a shame to get that to waste).
- b) Opening an issue for adding nyan_cat engine (and in that also adding the modules to define theme engines) and referencing that as backport from D8 (reference the D8 issue as parent).
Thanks!
Comment #87
SebCorbin CreditAttribution: SebCorbin at Makina Corpus commentedWoops, the test was failing and it was totally intended, so forget my addition
Comment #88
pounard@Fabianx
It don't think there is any benefit in splitting, it will only make the whole process longer, and we'd in the end, end up with the exact same change set; but by splitting it we make it harder to understand the purpose of the whole, and external viewers or followers would probably not get why this is important.
Moreover, it will also make it harder for people to apply the patch set waiting for it to be in core if it's splitted into many issues.
And, I would argue that now that it works, I don't see why we should roll it back and start all over again, it's just a complete loss of time, time that it is already hard to find hence to give to Drupal core.
I think we should keep this an atomic change and commit it as a whole, since everything in there is heavily coupled. Just write two lines into the commit message instead of one and everyone's gonna be happy with it :)
Comment #89
pounardJust to be clear, 4 persons already gave 8 hour each of their time to make it work. It now has full unit tests coverage, it backports whatever you asked us to backport, it has real life production site use case, and I seriously don't have time to play issue hide and seek right now. This is a good quality patch, let's finish this for once.
Comment #90
PolHi,
Updated patch with green tests.
Thanks @sebcorbin & @pounard for finding the issue.
Comment #92
PolLooks like there were some files missing in the previous patch.
Comment #93
SebCorbin CreditAttribution: SebCorbin commented@Fabianx: although I understand forward-porting to D8 merits its own issue, I don't see why we should open a child issue just for the sake of adding test data, i.e. only the file
modules/simpletest/tests/themes/engines/nyan_cat/nyan_cat.engine
, that would be a patch without tests and without logic.Comment #94
pounardAfter some time of pair debugging with @SebCorbin and phone conf with the 2 of us and @Pol, regarding that this latest patch includes all the things we agreed on us 3 altogether and that the patch passes tests, and fixes our bugs (at the exceptions of the Panels problem @Pol experienced, but that we agreed to fix in another issue, as it is unrelated), I'd say it's now RTBC.
Really @Pol many thanks for the time you took for this :)
@Fabianx it's your call now, I think that @Pol will open the aforementioned issues you'd like to see, nevertheless I do think this patch is ready.
Comment #95
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAdding nyan cat and the new hook is a task, this is a bug fix.
Unfortunately those need to be split up. If this patch is truly ready however, it means that only the bug fix and the test for the bug fix need to be removed from the last patch.
The patch can be left here for all to download until the child issue is committed.
Comment #96
PolHi,
As request by @FabianX, I've splitted the patch in different issues.
Here's the processing order to follow to fix this issue once for all:
In this issue, tests will stay red until the previous issues are committed.
Comment #97
pounardIt's actually the test of the bug fix, not a task.
Comment #98
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThese parts also belong in the child issue.
Only the subtheme and bugfix for subtheme with different engines belongs in this issue.
Comment #99
pounardWould have been easier to commit both in the same patch, we wouldn't have this kind of problem :)
Comment #100
pounardActually, the first one is related to this patch, since the testing theme exists only for our tests, as of now, but considering the second one, yes, it belongs to the other patch.
Comment #101
pounardAnd here it is, rebased on https://www.drupal.org/node/2825396#comment-11769346
So, not switching to needs review, I do wait for the other to be commited (else this one would fail).
Comment #102
pounardI am splitting the patches, but in order to gain time, including here the whole patch that includes #2825396: Enable modules to define theme engines for testing purposes.
Comment #104
PolHi all,
A small recap on this issue since the last days.
Pounard, Fabian and me worked on fixing the issue.
We had to split the issue in multiple issues. While splitting we discovered underlying stuff that needed to be fixed.
Here's the issue list:
Once the children are done, we will redo the patch in this issue with only the relevant part.
Comment #105
PolComment #106
Rene BakxAwesome work everybody :) Looking forward to closing this one after 4 years :)
Comment #107
pounard@Rene Bakx yes, me too! You shot first at this bug, I hope you will get the credits you deserve as well :)
Comment #108
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedI don't think that https://www.drupal.org/node/2826661 is a blocker for this issue as this (double extension) is a limitation that has been present since a long time already, so this can proceed now.
Comment #111
pounardOf course it failed, it needs to be rebased upon #2825396: Enable modules to define theme engines and #2826661: Let Drupal templates use single filename extension if possible.
Comment #113
PolNow that #2825396: Enable modules to define theme engines has been committed, here's an updated patch.
Comment #117
pounardWeird, few of the fails seem unrelated, they could be related but I ran them a second time to be sure.
Comment #118
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAs far as I understand this uses the wrong base theme as it contradicts the description.
I imagine a test-only patch would be working and not failing.
Could we attach a test-only patch to ensure the tests test the right thing?
Comment #119
pounardHum I reviewed the patch, and refactored the tests multiple times, I'm quite sure it does test right thing, but it's highly probable that english wording is wrong, indeed, we are both Pol and me not native english speakers.
Agree for the test-only patch, it's a good idea. I could be wrong too, I was probably too focused on the subject while debugging to have the best overview.
Comment #120
PolHi,
@Pounard, your patch in #101 is missing stuff that prevent the tests to be green, this is why I refactored it.
Regarding the wording, I agree.
Now, I don't understand why we have to make a tests-only patch. It will obviously fail right ?
Anyway, here's the patch.
Comment #121
PolComment #123
pounardActually, I do agree, because this patch has been worked for quite some time now, but ideally it's more a methodology than the saint graal, a test that fails proves that there's something to fix. But in the end, nothing proves that the test itself it right :)
I wouldn't be fair saying "yeah a test only patch is the best thing to do!" but in real life, it will reinsure Fabianx and other reviewers, so why not.
Comment #126
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedOkay, let me try to understand that:
In the IS the use case given is 'mothership' with 'mothertwig' as sub theme.
mothership uses php template and mother twig wants to use twig, but that fails due to the inheritance of the theme engine overwriting it.
If we test with a base theme of test_theme_nyan_cat would that not mean that we test with 2 themes that use both nyan_cat as engine?
That might still be useful in itself to test that, but unless I misunderstand something I don't think the test case is testing the bug described in the IS.
Thanks for the tests-only patch.
Comment #127
pounardIt actually tests that with no engine set in the info file, it gets the parent theme engine.
ThemeEngineNyanCatTestCase
tests that the .nyan-cat.html file overrides the .tpl.php one.ThemeEngineNyanCatSubThemeTestCase
tests that the subtheme, with no engine set, does inherit from the parent them if different from phptemplateTwo tests are missing:
The two tests I'm adding here are actually the one we wish to test: indeed, the real original bug is that Drupal can NOT handle two engines in the same runtime, and what it fixes is that Drupal will now be able to use multiple engines on the same page.
And once that is done, this should be it. I will do this maybe this weekend.
Comment #128
pounardThe reason why I was not worrying about the tests is because I have multiple projects in production as of today that actually do all this things altogether using the first patch before we started including the tests in it.
Comment #129
pounardHope this will be the last one, I added a few meaningful tests.
Comment #130
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedThanks for the additonal tests, pounard!
Comment #131
pounardYou're welcome, I had a couple of minutes to kill during an SQL import. This sounds very much RTBC in my opinion, just not switching the state myself since I wrote the patch.
Comment #132
PolComment #133
pfrenssenComment #134
pounardSo, how is it going ?
Comment #135
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedAssigning back to myself for review.
Comment #136
pounardIs this still stalling ?
Comment #137
Rene BakxPerhaps tag this as Drupal 7.60 target? Would be nice if this patch will be available together with https://www.drupal.org/node/2825396 so we can release the TFD7 module based version to replace the current theme_engine release.
Comment #138
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedIt is definitely a target for 7.60 - I just did not have the time, yet to review this further, but holidays are coming.
Comment #139
PolHi there,
Any news on this ?
Thanks.
Comment #140
Rene Bakxbit pissed, https://www.drupal.org/node/2826480 is useless without this patch as well :(
Comment #141
pounardYes, I would like very much to have this in core so I don't need to patch all my sites anymore :)
Comment #142
Delphine Lepers CreditAttribution: Delphine Lepers at Trasys for European Commission and European Union Institutions, Agencies and Bodies commentedAny hope to get this soon?
Comment #143
pounardAlong all the way to #129, many patches were posted, but one change, and the most important one, has sadly been dropped from the original patch: a fix that ensures that a parent theme with another engine than it's parent will keep its own instead of being forced to use the parent:
I think there's a missing test case somewhere, and now that I did upgraded to the latest patch on a new site, I encountered the bug.
Here is the updated patch.
Comment #145
pounardVoila! Seriously ouate de phoque the theme system is terrible, terrible.
I would like to fix it for good, but it's not possible, the 'engine' and 'owner' key are sometime in use from the $theme structure, and sometime from within the $theme->info array, in various/multiple places in system.module, module.inc, theme.inc and some other places around.
No, I will not fix this, it would make a huge patch. But I have fixed the inheritance now, I guess, and tests are all passing locally.
My problem compared to the patch in #129 is that because 'phptemplate' was set a default engine on all themes, the condition for inheritance were not always met, and a few other edge cases happened on my local box.
Comment #146
pounardComment #147
PolAll good for me.
Comment #148
pounardHum I experience some PHP warnings when I run updatedb in drush, I guess there are a few things to fix in my patch.
Comment #149
pounardAnd here it is an updated version, with the following changes:
I managed to actually remove code from a few functions, that was definitely unnecessary, since it was attempting to fix data that was already fixed by _system_rebuild_theme_data(): good side of things is that it actually reduces normal site runtime operations (but don't yay because it's very very insignificant on performances, like a drop of water in the sea). But hey, it makes it more readable in the end.
This should be the last patch, it fixes all my known bugs, all tests are still passing, and I documented code all over the patch to avoid people like me to search for hours for things that in the end, seem trivial, but definitely are not when it's not documented.
Hope the test passes on the testing environments, finger crossed :)
Comment #150
PolWow nice!
Can't wait to test!
Thanks!
Comment #152
pounardWeird thing, tests are passing on my box.
EDIT1: Actually they seem to be unrelated to theme system itself, but happen in various other tests, I would guess that something gets wrongly initialized in those conditions.
EDIT2: Only during upgrade tests, I'm debugging it.
EDIT3: Found it, during upgrade path from 6.x to 7.x, 6.x themes might not carry an 'engine' info key. I even think this is a problem of the tests themselves, although I'm not really sure about this.
EDIT4: Quite sure this is a problem with the upgrade path tests since Drupal 6 default themes are well formed and all carry the 'engine' key. But that's not a bug for this issue to fix. Writing the workaround as I speak.
Comment #153
pounardThis should do it (I hope). Tests haven't finished running on my box, but I think that some previously failing have passed.
Comment #154
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComments should (noramlly) begin with a capital letter and end with a full stop / period .
Comments should (noramlly) begin with a capital letter and end with a full stop / period .
Comment #155
pounardSeriously?
Comment #156
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #157
pounardThank you :)
Comment #158
pounardIf that matters, I just reapplied properly patch from #156 in a development site, working great so far. Still RTBC but I won't RTBC myself since I also wrote the most changing patch :)
Comment #159
pounardOne more site working with it.
Comment #160
PolComment #161
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedIf these bugs affect Drupal 8, they still need to be fixed there first. That's been mentioned several times in this issue. It appears to me that most of these bugs do affect Drupal 8 (with the possible exception of the one that's tested in #2825382: Add new tests for testing themes and subthemes engine inheritance), so based on that this can't be ready to commit to Drupal 7 yet.
To determine that they probably affect Drupal 8, I looked through changes in the patch here and then found the corresponding code in Drupal 8:
I stopped looking after that, but there may be more.
***
In any case, the Drupal 7 patch itself looks pretty nice and I think there are some great improvements in there. But a few issues I noticed while reading through it:
Several things about the above:
array($theme) + list_themes()
construct does not look right and is going to result in this running twice for that particular theme.I don't think we can remove this global variable - it's a documented part of the public API. Why not just leave it in place and continue to set it to the correct value, even if core itself no longer uses it anymore?
Although this is not a function that is expected to be called publicly, I still don't see any reason to change the API. Why not just mark $theme_engine as a deprecated parameter - or maybe even have it continue to behave the way it used to but have the calling functions in core always pass nothing in for it?
I am not sure what is going on here (it could certainly use a code comment), and in particular $current_theme always seems to be NULL no matter what (unless I'm reading this wrong it's only ever reassigned via
$current_theme = $current_theme
???!!!!)Since (as the code comment says)
$themes[$key]->engine
never winds up in the database, what is the purpose of changing this function to set that at all? Currently, it looks to me like list_themes() is responsible for setting this property, which it does always (regardless of whether it gets its data from _system_rebuild_theme_data() or from the database) so it's not obvious to me what the benefit is of also setting it in _system_rebuild_theme_data().(relatively minor) There's already another test case right above this with the same "Theme engine test" name. One or both should be renamed to something more specific.
(minor) Here and many other places... The correct spelling is "overridden".
Comment #162
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedComment #163
pounard@David_Rothstein As I very much would like to clean this up, I have no time to do it, latest iteration cost me a full day; not counting the previous ones, for such a small bug. I'll try to give accurate answers, please excuse me if I am wrong about some points, because it's been months since I didn't touch this.
It does not initialize all themes, but their engines. It's legit to initialize all engines since we are not going to know which one we'll use at this point, and we need them to be early initialized. This old Drupal spaguetti code is terrible, sadly, and that's the best I could come up with. Best we can do here, I supposed, is to avoid double engine initialization.
Once again, engines, not themes, and yes I guess the
array($theme) +
is not necessary anymore.Hum, wrong comment, too many iterations on this patch. The comment should be dropped. The order here means nothing, because it's about engines and not themes.
We could leave the variable, but it won't mean anything anymore in the case you have a theme parenting tree with more than one engine, but OK, I don't care about keeping the global here.
It'd just keep an inconsistent method signature, the theme code is so ugly and so old, I'd like to keep the unused variable removal. Let me explain: I know 7.x core pretty deeply, and I have a few years of patching, and core contributing behind me, and yet I had to literally step debug a complete day to fully understand what this central method was really doing. Let's not keep the cruft it doesn't help anybody.
Fun thing, I am not sure myself :) There's a few typos in there, that would explain why I had some troubles with unit tests. I might have to rework this part.
list_theme()
does stuff at runtime whereas_system_rebuild_theme_data()
will cache the info array in the database, hence the code being moved in here: now that we are initializing theme engines, we gain a bit of speed in there. And another thing to consider is that in actual stable core, it's unclear who and when 'engine' and 'owner' are initialized: the whole point of this code, even if too verbose, is to make it explicit and at one and only one single place.Comment #164
simon.mellerin CreditAttribution: simon.mellerin at Makina Corpus commentedHi,
Here is some modifications to avoid 'warning' if you apply the patch before you install Drupal
Comment #165
dan2k3k4 CreditAttribution: dan2k3k4 at Amazee Labs commented@simon.mellerin your patch seems to contain (and create) the file `old.patch`
Wondering what patch file should I be using?
Comment #166
MustangGB CreditAttribution: MustangGB commentedBumping target based on #161 mentioning this needs to be fixed in D8 first.