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.
Task
Convert theme_ functions to Twig templates.
Remaining
- theme_ function -> Twig conversions (and preprocess function additions or changes) moved over from the existing conversion issue
- Patch review
Theme function name | Conversion status |
---|---|
theme_theme_test | converted |
theme_theme_test_foo | converted |
Related Issues
#1898458: theme_test.module - Convert PHPTemplate templates to Twig
#1757550: [Meta] Convert core theme functions to Twig templates
#1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Comment | File | Size | Author |
---|---|---|---|
#38 | interdiff.txt | 811 bytes | joelpittet |
#38 | 1987414-38-twig-theme_test.patch | 3.26 KB | joelpittet |
#36 | 1987414-36-twig-theme_test.patch | 3.9 KB | joelpittet |
#36 | interdiff.txt | 830 bytes | joelpittet |
#32 | theme-test-twig-conversion-1987414-32.patch | 2.9 KB | chipway |
Comments
Comment #0.0
star-szrUpdated issue summary.
Comment #1
c4rl CreditAttribution: c4rl commentedPer #1757550-44: [Meta] Convert core theme functions to Twig templates, retitling to indicate this issue applies to theme_ functions rather than templates. See #1898458: theme_test.module - Convert PHPTemplate templates to Twig Assigned to: widukind for template conversion.
Comment #1.0
c4rl CreditAttribution: c4rl commentedUpdated issue summary.
Comment #2
widukind CreditAttribution: widukind commentedComment #3
widukind CreditAttribution: widukind commentedComment #4
widukind CreditAttribution: widukind commentedComment #4.0
widukind CreditAttribution: widukind commentedList of functions
Comment #5
star-szrLooks good, thanks @widukind!
Comment #6
alexpottComment #7
widukind CreditAttribution: widukind commentedComment #8
widukind CreditAttribution: widukind commentedre-tagged with "Needs profiling"
Comment #9
minneapolisdan CreditAttribution: minneapolisdan commented#3: 1987414-3.patch queued for re-testing.
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedWorking on this during the Portland sprint.
Comment #12
Sean Charles CreditAttribution: Sean Charles commentedRerolled
Comment #13
OpenChimp CreditAttribution: OpenChimp commentedprofiling this now.. hopefully the patch passes tests
Comment #14
OpenChimp CreditAttribution: OpenChimp commentedProfiling looks good so long as the patch passes the tests:
=== 8.x..8.x compared (519ffea2643cf..519fff787bd4d):
ct : 40,580|40,580|0|0.0%
wt : 377,639|377,895|256|0.1%
cpu : 334,533|335,159|626|0.2%
mu : 50,206,616|50,206,616|0|0.0%
pmu : 50,271,728|50,271,728|0|0.0%
Profiler output
=== 8.x..1987414 compared (519ffea2643cf..519fffa9aa250):
ct : 40,580|40,580|0|0.0%
wt : 377,639|378,267|628|0.2%
cpu : 334,533|335,045|512|0.2%
mu : 50,206,616|50,206,712|96|0.0%
pmu : 50,271,728|50,272,256|528|0.0%
Profiler output
---
ct = function calls, wt = wall time, cpu = cpu time used, mu = memory usage, pmu = peak memory usage
The registry has been rebuilt. [success]
'all' cache was cleared in self
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #16
pplantinga CreditAttribution: pplantinga commentedReroll + fix errors: templates add a newline at the end.
Comment #17
star-szrThanks @pplantinga! I don't really think this particular patch should be held up on profiling :)
For now, let's remove these lines per #2013094: [policy adopted, patch needed] Stop saying '@see template_preprocess()' in every twig file.
Comment #18
RainbowArrayHere is a revised patch with the change suggested in #17.
Comment #19
RainbowArrayChanging to needs review. Come hither, Testbot!
Comment #20
RainbowArrayHere's an interdiff for the change in #18.
Comment #21
joelpittetThanks @mdrummond!
This looks good, profiling looks good. #14
RTBC:)
Comment #22
star-szrProfiling results are not correct (there should be more function calls, thanks @OpenChimp for trying though!) but I really don't think this one needs profiling. Thanks @mdrummond for the patch tweaks.
Comment #23
Eric_A CreditAttribution: Eric_A commentedThis is a conversion issue. Why would it be OK to just change output and tests without any discussion? I'd say it's probably best to not change output at all in this issue and just fix the template.
Comment #24
star-szrThe alternatives within scope here that I can think of:
@Eric_A, we have adjusted for whitespace in other tests as part of #1757550: [Meta] Convert core theme functions to Twig templates and #1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch, so this is nothing new… I'm fine with whatever approach is taken though.
Comment #25
joelpittetI'm a fan of the
{# Comment control trick #}
because it's got relatively low processing to do vs spaceless (which is doing the same thing + removing whitespace inside).I'd like to recommend we use the comment trick to fix all twig templates with this EOF newline character issue. @Cottser, we can discuss this more later but maybe I should add that to Twig Coding Standards http://drupal.org/node/1823416?
Comment #26
joelpittetOh yeah and thanks @Cottser for catching the profiling results were off.
Comment #27
star-szrSo this needs a reroll and should be updated to remove the test changes and use the dummy comment at the end of the template to remove the extra newline.
Comment #28
thomas.fleming CreditAttribution: thomas.fleming commentedComment #29
thomas.fleming CreditAttribution: thomas.fleming commentedComment #30
pplantinga CreditAttribution: pplantinga commentedHow about this?
Comment #31
star-szrThank you very much @pplantinga :)
A few of us (myself, @joelpittet, @Sean Charles) discussed changing tests vs. working around the whitespace, and we concluded that adding this dummy comment (or adding spaceless tags) to remove the extra newline is more confusing and not practical, especially in this case.
I would rather keep our core templates clean, lean and mean than complicate them to fit within the bounds of existing tests.
The addded newline is a natural result of the conversion process, since we are moving from a theme function (PHP function concatenating strings) to a template file (which needs a newline at EOF for Git reasons).
So at this time I think the best way forward with this issue and similar issues is to just change the test to add the newline (or make other whitespace adjustments as needed) for the reasons stated above.
Comment #32
chipway CreditAttribution: chipway commentedRemove white space comment in theme-test-foo.html.twig.
Joel told to do this.
Comment #33
pplantinga CreditAttribution: pplantinga commentedLooks like it works without changing tests? Cool.
Do we still need profiling?
Comment #34
star-szrThanks! We need to remove theme_theme_test_foo(). And likely update the tests as a result. I ran Drupal\system\Tests\Theme\ThemeTest locally and did get 1 fail and 1 exception.
Comment #35
joelpittet#32: theme-test-twig-conversion-1987414-32.patch queued for re-testing.
Comment #36
joelpittet@Cottser ran the test locally without a fail/exception Was that through the UI or CLI?
Attached is that function removed.
Comment #37
star-szrIt was through the UI, but testbot likes this so we should be good :) Just need to remove the rdf-metadata.html.twig template from the patch.
Comment #38
joelpittetWhoops, thanks for spotting the extra sneaky file.
Comment #40
star-szr#38: 1987414-38-twig-theme_test.patch queued for re-testing.
Comment #41
pplantinga CreditAttribution: pplantinga commentedLooks good
Comment #42
webchickWellll, hold up now.
We're still going to have some theme functions in D8 at the point it ships, in a few areas where performance are concerned. Correct?
If so, then I don't think we can convert (at least all of) these tests, because we still need test coverage to ensure theme functions work. This test module already has coverage for template files, so it seems these theme functions are deliberately theme functions.
Or am I missing a cluestick?
Comment #43
star-szrYeah, I'd thought about that as well @webchick and it's a great point. Postponing for now and if we are somehow able to get rid of all theme functions before release then we can work on this again.
Comment #43.0
star-szrUpdated issue summary.
Comment #44
star-szrComment #45
joelpittetWe will get the functions out before 8.0.x but we will need to keep this test in for posterity until 9.0.x
Comment #46
star-szrBut not yet.
Comment #47
catchShouldn't we just be removing the tests here along with the theme function functionality?
If we need to convert the theme function to a template, that suggests we're missing coverage elsewhere and could be done in 8.1.x.
Comment #48
catchRe-titling for now.
Comment #49
joelpittet@catch Yes, if this is for 9.x then removing the test coverage would appropriate.
Comment #50
catchMarking this as duplicate of #2716163: [META] Remove deprecated classes, methods, procedural functions and code paths outside of deprecated modules on the Drupal 9 branch. When we remove the bc layer for theme functions, these tests will break and we can remove them.