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

#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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

star-szr’s picture

Issue summary: View changes

Updated issue summary.

c4rl’s picture

Title: theme_test.module - Convert PHPTemplate templates to Twig » theme_test.module - Convert theme_ functions to Twig

Per #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.

c4rl’s picture

Issue summary: View changes

Updated issue summary.

widukind’s picture

Assigned: Unassigned » widukind
widukind’s picture

Status: Active » Needs work
FileSize
3.31 KB
widukind’s picture

Status: Needs work » Needs review
widukind’s picture

Issue summary: View changes

List of functions

star-szr’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks @widukind!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +needs profiling
widukind’s picture

Assigned: widukind » Unassigned
Issue tags: -needs profiling
widukind’s picture

Issue tags: +needs profiling

re-tagged with "Needs profiling"

minneapolisdan’s picture

Status: Needs work » Needs review
Issue tags: -needs profiling, -Twig

#3: 1987414-3.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +needs profiling, +Twig

The last submitted patch, 1987414-3.patch, failed testing.

Anonymous’s picture

Assigned: Unassigned »

Working on this during the Portland sprint.

Sean Charles’s picture

Assigned: » Unassigned
Status: Needs work » Needs review
FileSize
3.35 KB

Rerolled

OpenChimp’s picture

profiling this now.. hopefully the patch passes tests

OpenChimp’s picture

Issue tags: -needs profiling

Profiling 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

Anonymous’s picture

Status: Needs review » Needs work
Issue tags: +needs profiling
pplantinga’s picture

Status: Needs work » Needs review
FileSize
4.32 KB

Reroll + fix errors: templates add a newline at the end.

star-szr’s picture

Status: Needs review » Needs work
Issue tags: -needs profiling +Novice

Thanks @pplantinga! I don't really think this particular patch should be held up on profiling :)

+++ b/core/modules/system/tests/modules/theme_test/templates/theme-test-foo.html.twig
@@ -0,0 +1,14 @@
+ * @see template_preprocess()

+++ b/core/modules/system/tests/modules/theme_test/templates/theme-test.html.twig
@@ -0,0 +1,15 @@
+ * @see template_preprocess()

For now, let's remove these lines per #2013094: [policy adopted, patch needed] Stop saying '@see template_preprocess()' in every twig file.

RainbowArray’s picture

Here is a revised patch with the change suggested in #17.

RainbowArray’s picture

Status: Needs work » Needs review

Changing to needs review. Come hither, Testbot!

RainbowArray’s picture

FileSize
1.04 KB

Here's an interdiff for the change in #18.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

Thanks @mdrummond!

This looks good, profiling looks good. #14

RTBC:)

star-szr’s picture

Profiling 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.

Eric_A’s picture

Status: Reviewed & tested by the community » Needs work

This 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.

star-szr’s picture

The 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.

joelpittet’s picture

I'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?

joelpittet’s picture

Oh yeah and thanks @Cottser for catching the profiling results were off.

star-szr’s picture

Issue tags: +Novice, +Needs reroll

So 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.

thomas.fleming’s picture

Assigned: Unassigned » thomas.fleming
thomas.fleming’s picture

Assigned: thomas.fleming » Unassigned
pplantinga’s picture

Status: Needs work » Needs review
FileSize
2.93 KB

How about this?

star-szr’s picture

Issue tags: -Needs reroll

Thank 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.

chipway’s picture

Remove white space comment in theme-test-foo.html.twig.

Joel told to do this.

pplantinga’s picture

Looks like it works without changing tests? Cool.

Do we still need profiling?

star-szr’s picture

Status: Needs review » Needs work

Thanks! 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.

joelpittet’s picture

Status: Needs work » Needs review
joelpittet’s picture

Issue tags: -Novice
FileSize
830 bytes
3.9 KB

@Cottser ran the test locally without a fail/exception Was that through the UI or CLI?

Attached is that function removed.

star-szr’s picture

Status: Needs review » Needs work

It 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.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
3.26 KB
811 bytes

Whoops, thanks for spotting the extra sneaky file.

Status: Needs review » Needs work
Issue tags: -Twig

The last submitted patch, 1987414-38-twig-theme_test.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review
Issue tags: +Twig

#38: 1987414-38-twig-theme_test.patch queued for re-testing.

pplantinga’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Wellll, 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?

star-szr’s picture

Status: Needs review » Postponed

Yeah, 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.

star-szr’s picture

Issue summary: View changes

Updated issue summary.

star-szr’s picture

joelpittet’s picture

Version: 8.0.x-dev » 9.x-dev
Status: Postponed » Active

We will get the functions out before 8.0.x but we will need to keep this test in for posterity until 9.0.x

star-szr’s picture

Status: Active » Postponed

But not yet.

catch’s picture

Shouldn'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.

catch’s picture

Title: theme_test.module - Convert theme_ functions to Twig » Remove test coverage for theme functions
Issue tags: +Needs issue summary update

Re-titling for now.

joelpittet’s picture

@catch Yes, if this is for 9.x then removing the test coverage would appropriate.

catch’s picture

Status: Postponed » Closed (duplicate)

Marking 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.

Version: 9.x-dev » 9.0.x-dev

The 9.0.x branch will open for development soon, and the placeholder 9.x branch should no longer be used. Only issues that require a new major version should be filed against 9.0.x (for example, removing deprecated code or updating dependency major versions). New developments and disruptive changes that are allowed in a minor version should be filed against 8.9.x, and significant new features will be moved to 9.1.x at committer discretion. For more information see the Allowed changes during the Drupal 8 and 9 release cycles and the Drupal 9.0.0 release plan.