Part of meta-issue #1788918: [GTD] [META] Prepare for Twig main engine core inclusion until December 1
While developing for twig, I found that I can't put a .twig file in core/modules/system because it won't be picked up. In fact modules can only use the default phptemplate engine. To be able to do incremental work on template conversion in core, it needs to temporarily support two theme engines for modules (phptemplate and twig).
After Twig is fully implemented, the use of two theme engines will be fixed by #1805592: Remove static double theme engine code once all module provided .tpl.php files are converted to twig and twig is default so that there will only be one theme engine before release of 8.x again.
Comments
Comment #1
chx CreditAttribution: chx commentedTagging.
Comment #2
jenlamptonmore tagging
Comment #3
podarok#0 looks good for me
Comment #4
chx CreditAttribution: chx commentedmodule_theme_engine.patch queued for re-testing.
Comment #6
catchThis seems at least major to me.
Comment #7
Fabianx CreditAttribution: Fabianx commentedNew patch for this:
* Make theme_engine the default engine if different from default engine.
* Make it possible to fallback to default engine if no template file was found for the current theme engine
This allows to set for example:
engine = twig in a theme and it will also find a node.twig in the core/modules/node/node.twig
Example searches are:
check: node.twig
check: node.tpl.php
This is a blocker for #1696786: Integrate Twig into core: Implementation issue.
Comment #8
Fabianx CreditAttribution: Fabianx commentedPriority back to major as per #6.
Here are some testing instructions from IRC:
Comment #9
tlattimore CreditAttribution: tlattimore commentedI have functionally tested and reviewed the patch #7 and can confirm it works as described.
I tested as follows:
* Applied patch from #7
* Then applied patch from http://drupal.org/files/core-Integrate-twig-into-core-1696786-27_0.diff
-- This modifies the stark theme to use the twig engine and therefore call *.twig templates, this step is simply to test that the changes work correctly
* Then I MOVED (not copied) the node.twig from stark to core/modules/node/
After following these steps (and clearing the cache) the node.twig was then being called from core/modules/node/ correctly.
RTBC!
Comment #10
podarok#7 looks good for me too
Comment #11
sun...that looks like a lot of additional processing for every single theme() call on a template. Any chance to cache this always static theme engine info?
If there's no obvious way and existing facility, then let's create a major follow-up issue to introduce one.
lettercase typo
Comment #12
catchThis needs tests as well.
Comment #13
Fabianx CreditAttribution: Fabianx commentedAfter discussion with catch:
This needs a different approach and tests for multiple engines.
Comment #14
Fabianx CreditAttribution: Fabianx commentedNeeds review: ONLY FOR TESTBOT
This is including a bad, bad, bad hack and hardcodes twig.
Description of changes:
This will allow to use any registered engines parallel at the same time.
Engine registering is the problem and does not work as a module_invoke_all is not possible and an engine_invoke_all does not exist.
As this would need a follow-up issue anyway to move engines to the plugin system, we need to do the follow-up before this issue can go in.
Will search for / open issue now.
Comment #15
Fabianx CreditAttribution: Fabianx commentedHmmm, without the phptemplate.engine change this will never run the new code path.
New patch including phptemplate.engine attached.
Again: ONLY FOR TESTBOT. Comments from #14 apply.
Comment #16
Fabianx CreditAttribution: Fabianx commentedOkay, back to the drawing board:
Goals this patch wants to achieve:
* Current engine functionality works as is and is _not_ changed
* Only for modules will core support temporarily several engines (twig and phptemplate as followup)
* The engines are hardcoded and are also loaded by default - if they exist.
* Drupal implements drupal_get_theme_engines for this
* The detection of module .twig / .tpl.php files is done in _registry_rebuild like in current patch.
=> Only if its a module, will $info['template_file'] be set and only in that case will it be a different engine then the default one.
Comment #17
Fabianx CreditAttribution: Fabianx commentedComment #18
Fabianx CreditAttribution: Fabianx commentedNew approach with hardcoded twig as second engine only for modules.
Falls back gracefully if twig.engine is not yet available and templates are printed via phptemplate instead as verbatim ...
Explanation of patch
This is a temporary patch and will be removed before release per #1805592: Remove static double theme engine code once all module provided .tpl.php files are converted to twig and twig is default.
First of all both phptemplate.engine and twig.engine need to be loaded at all times for modules to work with both template types. phptemplate is the default, so it is always loaded.
Twig is the temporary additional engine, so it is loaded always in _drupal_theme_initialize if twig.engine exists.
Second the _theme_process_registry function is changed, to support only for type = module temporarily two theme engines and if a template could be found via file_exists both the engine and the template_file is stored as part of the registry.
Third in case of a module, the engine is taken from $info['engine'] if it exists and the engine is looked up _like_ for themes. Additionally if $info['template_file'] is set, this is used instead.
Thanks goes to chx for mentoring :-).
This is the simplest way that we could come up with to unblock TWIG in Core.
Comment #19
cosmicdreams CreditAttribution: cosmicdreams commentedThis is a simple temporary patch to facilitate current work to get Twig into core. It's not intended to be included in the final d8 release. In that regard, it looks RTBC to me.
Comment #19.0
cosmicdreams CreditAttribution: cosmicdreams commentedUpdated issue summary.
Comment #19.1
cosmicdreams CreditAttribution: cosmicdreams commentedupdated summary to include follow up.
Comment #20
RobLoachAlthough I understand putting in a temporarary fix to get around Drupal's gross template engine system, but could try and make the engine system a bit less-gross in the process?
[EDIT] Was working on #304486: Theme Engines as Modules a while ago. Might be worth another look.
Comment #21
Fabianx CreditAttribution: Fabianx commented@sun, #11:
Yes, already without this patch there is processing going on by run-time by calling function_exists, but most of this is needed due to some other things. Function_exists seems to be not too expensive. Could be changed some time.
@Rob Loach:
I am happy to do that as part of another issue, but we don't have the time at the moment for this PATCH, because this blocks #1696786: Integrate Twig into core: Implementation issue and we need to get twig in ASAP to unblock other work that needs review, testing, etc.
I tried hard to fix the engine system while doing so, but it is very complex, would need a pleora of new tests (that are not there currently) and is totally away from the goals of the twig initiative.
What we need for TWIG to be a success is this to get commited and then more reviews on #1696786: Integrate Twig into core: Implementation issue and get that commited as well.
I am removing "needs tests" tag for this issue as we need twig.engine in to actually test this. We will provide proper tests that .twig and .tpl.php files are rendered correctly as part of #1696786: Integrate Twig into core: Implementation issue.
A manual review will find that core still finds the .tpl.php files for modules with this patch included.
Comment #22
chx CreditAttribution: chx commentedIMO this looks good , it should be merged into #1696786: Integrate Twig into core: Implementation issue because then a) it can be tested b) the function_exists hunk removed so we do not need to argue over it.
Comment #23
jwilson3Merged here: #1696786-55: Integrate Twig into core: Implementation issue
Comment #23.0
jwilson3Explain issue a little better