Spin-off from #1757550: [Meta] Convert core theme functions to Twig templates

We decided in #1804698: Consider using *.html.twig filename convention to use .html.twig instead of the default .twig file extension for Drupal's Twig theme engine. Patch forthcoming.

Comments

steveoliver’s picture

Title: Twig theme engine use .html.twig file extension » Use .html.twig instead of .twig file extension

Title.

steveoliver’s picture

Status: Active » Needs review
StatusFileSize
new19.2 KB
tstoeckler’s picture

You can roll the patch with git diff -C -M which reduces the patch size and makes it easier to review.

Status: Needs review » Needs work

The last submitted patch, drupal_twig-engine-use-html-twig--1900458-2.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review
StatusFileSize
new3.32 KB
new6.1 KB

Fixed one of the tests, but the test that's failing in Drupal\system\Tests\Theme\ThemeTestTwig->testTemplateOverride() is failing in the sandbox as well.

Patch re-rolled with git diff -C -M as suggested in #3.

webchick’s picture

Can you explain why we're doing this? I'm looking at the official documentation at http://twig.sensiolabs.org/pdf/Twig.pdf and all I see are references to foo.twig, not foo.html.twig. Why are we inventing a Drupalism here?

star-szr’s picture

@webchick - I just updated the issue summary to include a reference to #1804698: Consider using *.html.twig filename convention

webchick’s picture

Ok, awesome. Thanks for the reference! :)

Status: Needs review » Needs work

The last submitted patch, 1900458-5.patch, failed testing.

steveoliver’s picture

Status: Needs work » Needs review

Thanks, Cottser. I know you just signed off -- gonna work on getting this passing.

star-szr’s picture

StatusFileSize
new1.54 KB
new7.48 KB

Okay, managed to track this down. The failing test is only passing on HEAD because the template file is named .twig, not .html.twig. To really fix this, a hardcoded ".tpl" needs to be removed, and a couple strpos() need to be changed to strrpos().

#1678808-1: Defining a new theme engine with templates without .tpl.[template extension] breaks template suggestions (committed as part of #1696786: Integrate Twig into core: Implementation issue) removed one instance of hardcoded .tpl, and in the sandbox @Fabianx removed the other hardcoded .tpl instance with the same technique.

- if (($pos = strpos($template, '.tpl')) !== FALSE) {
+ if (($pos = strpos($template, '.')) !== FALSE) {

Previously strpos was searching for .tpl so it had a definite boundary and worked fine. Now that it's just searching for "." it should use strrpos instead to allow for template files with extra periods in them - like theme_test.template_test.tpl.php or theme_test.template_test.html.twig.

I'm not sure if we should add a test somewhere to make sure periods can be used in template suggestions. See also #1886448: Rewrite the theme registry into a proper service

@Fabianx should be credited as well on this commit since it incorporates his commit from the sandbox.

steveoliver’s picture

Assigned: steveoliver » Unassigned

Thanks, Cottser (and Fabianx). You rock.

star-szr’s picture

StatusFileSize
new2.3 KB
new8.24 KB

If you apply only the interdiff from #11 (without any .twig -> .html.twig changes) then the test will fail because the template file doesn't have an "extra" extension as in .tpl.php and .html.twig, so something like theme_test.template_test.haml would fail because the last part gets stripped away mistakenly. Here's a slightly better idea that just replaces the whole extension in the filename based on the $extension passed into drupal_find_theme_templates(), no strpos() of any sort needed.

Interdiff is from #5.

Happy to move this change into a separate issue if that makes more sense.

Status: Needs review » Needs work

The last submitted patch, 1900458-13.patch, failed testing.

star-szr’s picture

Failure in Drupal\openid\Tests\Upgrade\OpenIDAuthmapUpgradePathTest - looks like #1893800: Something is very, very wrong with update.php / upgrade tests... demons suspected, sending for a re-test.

star-szr’s picture

Status: Needs work » Needs review

#13: 1900458-13.patch queued for re-testing.

catch’s picture

Priority: Normal » Critical

This is apparently blocking Twig conversion, so bumping priority.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, and the diffstat is nice since we're removing special casing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

jenlampton’s picture

woot :)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Adding reference to .html.twig issue