Closed (works as designed)
Project:
Drupal core
Version:
8.6.x-dev
Component:
theme system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Mar 2019 at 14:18 UTC
Updated:
7 Oct 2025 at 11:02 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
amateescu commentedI think this is a duplicate of #3040210: Updating twig/twig to v1.38.2 (included in Drupal 8.6.11) causes fatal error when embed tags are used in templates.
Comment #3
crash_springfield commentedI posted this in the referenced issue and was told to create a new issue because none of the patches worked. This is not a duplicate. This is a different issue.
Comment #4
cilefen commentedWhat version of Twig is installed in the site?
Comment #5
crash_springfield commented@cilefen v1.38.2
Comment #6
cilefen commentedI can't reproduce it.
Comment #7
jproctorError messages above are missing full template filenames. For posterity (and searchability):
/admin/modules/uninstall => core/themes/stable/templates/admin/system-modules-uninstall.html.twig
/admin/reports/dblog => core/themes/classy/templates/views/views-mini-pager.html.twig
/admin/reports/updates => core/themes/stable/templates/admin/update-project-status.html.twig
I’m seeing this too, and also in my user-facing theme for some content types but not others. Since it’s not easy to reproduce, I’m going to go spend a little time reading #3039408: Updating twig/twig to v1.38.0 or v1.38.1 causes fatal error and #3040210: Updating twig/twig to v1.38.2 (included in Drupal 8.6.11) causes fatal error when embed tags are used in templates and see if I can figure out how to diagnose a little further.
Comment #8
jproctorI worked on dblog first, and tracked it down to the Twig node that was failing:
Project_trans_Node( count: body: Twig\Node\Node( 0: Twig\Node\TextNode(data: ' Page ') 1: Twig\Node\PrintNode( expr: Twig\Node\Expression\FilterExpression( node: Twig\Node\CheckToStringNode( expr: Twig\Node\Expression\GetAttrExpression(type: 'any', is_defined_test: false, ignore_strict_check: false, disable_c_ext: false node: Twig\Node\Expression\NameExpression(name: 'items', is_defined_test: false, ignore_strict_check: false, always_defined: false) attribute: Twig\Node\Expression\ConstantExpression(value: 'current') arguments: Twig\Node\Expression\ArrayExpression() ) ) filter: Twig\Node\Expression\ConstantExpression(value: 'drupal_escape') arguments: Twig\Node\Node( 0: Twig\Node\Expression\ConstantExpression(value: 'html') 1: Twig\Node\Expression\ConstantExpression(value: NULL) 2: Twig\Node\Expression\ConstantExpression(value: true) ) ) ) 2: Twig\Node\TextNode(data: ' ') ) plural: options: )... which corresponds with this section of the template:
{% trans %} Page {{ items.current }} {% endtrans %}When I remove the call to
{% trans %}, it works fine.Same issue in the other two files: it fails on calls to
{% trans %}in the template. Thetfilter was fine, though.I found the same problem in /node/add, but there are other instances of
{% trans %}that don’t seem to have a problem (at least for me, using Seven as the admin theme).According to the Translation API Overview page, the
{% trans %}block should be “supported (as defined by the Twig i18n extension)”. I assume that means the code in core/lib/Drupal/Core/Template/TwigTransTokenParser.php is supposed to be able to behave the same way as the actual Twig i18n extension, not that said extension is installed (it isn’t).I tried adding watchdog lines to the top of its
parse()andcheckTransString()functions, and neither was called in the course of rendering one of the pages that throws an error. I know it is being created by thegetTokenParsers()function in TwigExtension, so I started looking in Twig code again.I suspect there is at least one error in Twig itself: in the
getTags()function in src/Environment.php (which is the superclass of Drupal’s TwigEnvironment), it calls$this->getTokenParsers()->getParsers(), but every occurrence ofgetTokenParsers()everywhere returns a simple array, not an object that will respond to methodgetParsers(). This is not the problem we’re having, though.I found the place where the parsers are attached to the tags, and finally figured out what’s going on. Drupal’s native TwigTransTokenParser is being clobbered by the Unified Twig Extensions module, which is not in Contrib. Mine was installed by Emulsify, which is.
This module looks in the theme for Twig extensions and adds them. Emulsify defines a trans tag extension, and it was being loaded second, and its code relies on the
nameattribute (which was recently removed from Twig). Thus the error message.Emulsify version 2.4 renamed the file, which removes the conflict in a way that I don’t fully understand, but which worked for me:
Solution?
@crash_springfield, if you have an Emulsify-based theme, look in your user-facing theme folder(s), and you should have components/_twig-components/tags/trans.tag.php . Rename this to pl_trans.tag.php and replace all occurrences of
Project_transwithProject_pl_trans(this will create things likeProject_pl_trans_NodeandProject_pl_trans_TokenParser). Then, also in your theme folder(s), make sure the file is updated in pattern-lab/source/; in my case that folder is a symlink to components/, so there was nothing else to do. And then, obviously, clear cache.Emulsify has also updated the names of filters and functions, so you may want to get caught up on those as well if yours don’t have the pl_ prefix.
Comment #9
crash_springfield commented@jproctor Thanks for the advice! I just managed to narrow it down to vaguely knowing there was an issue with my theme. This is exactly it!
Comment #10
crash_springfield commentedIssue was with an outdated Emulsify dependency.
Comment #11
jeromewiley commentedI'm using Canna (also called Cannan) theme, which I believe is not based on Emulsify. How to fix this? Will do a filename search for trans.tag.php in my codebase for now.
Comment #12
jeromewiley commentedNo files found by that name. I'm getting the exact same error as reported above after attempting to upgrade from 8.6.10 -> 8.6.13 and twig from 1.37.1 -> 1.38.2.
Please advise fix.
Comment #13
cilefen commentedDoes the theme code reference Twig_Node or Twig\Node\Node in its codebase?
Comment #14
jproctorSomething—either your theme or a module—is using code like
getAttribute('name'). Find that and you’ll find what’s causing the error.Challenge 1: it might not be
'name'; it might be"name"or some variable that evaluates to that string, possibly in a loop.Challenge 2: when you find it, you still have to figure out how to fix it, but at least it gives you a better place to look.
Comment #15
guardiola86 commentedIn my case, I've upgraded to the latest core version: 8.6.13 and I'm using twig version 1.38.4. I've commented out this line in web/core/themes/classy/templates/content/node.html.twig:
{% trans %}Submitted by {{ author_name }} on {{ date }}{% endtrans %}After removing that line, I don't get the error again. Any idea how to fix this?
Comment #16
cilefen commentedComment #17
lalop commentedI have the same issue on page /admin/structure/block/block-content
Comment #18
BigEd commentedI spent a bit of time trying to debug this, looks like
{% trans %}is where it does not like the use ofgetAttribute('name')in the new version of Twig.This must be something that we are doing in a module or a theme Twig version 1.38.4 does not like, so have been through the theme and module functions and so far they look correct.
I can remove
{% trans %}from the node.tpl.php and add this to the theme and this gets the site running but this is not really a solution to fixing the issue and is just masking the problem.I suspect we all using some sort of implementation of twig module like Pattern labs that is causing the twig to chuck its toys out, so If I can narrow down where the issue is I can make a patch.
Comment #19
berdirCore doesn't have any problems with %trans, there are some contrib modules/themes that overrride that, so check the theme and modules that you are using. I'm pretty sure that this is nothing that can be fixed in core. There have been problems with that before, see for example #2895187: Twig_Error_Syntax: The text to be translated with "trans" can only contain references to simple variables in Twig_Extensions_TokenParser_Trans->checkTransString()
Comment #20
BigEd commentedYes, sorry i don't think I made that very clear. As you say Berdir it's not core its a theme issue.
Comment #21
d70rr3s commentedHi, I've step on this too, in my case I'm using a theme based on Acquia's Cog starter theme (didn't find any whacky-hacky around their .theme) and I'm not using any modules to extend Twig engine beyond core's support. The snippet of code throwing the error (see screenshot 1) is the following:
If I remove the
{{ year }}it just works fine. I can confirm that year is a simple var, just a string with the current year using 4 digits format (see screenshot 2).In my case just fallback to use the
tfilter and is currently working but it would be nice to figure out whats going on for more complex templates like emails.Ah almost forgot: Core 8.6.10, Twig 1.38.4
Comment #22
d70rr3s commentedHi again, this issue is affecting also core themes not only custom themes (see screenshot) and this seems to be bogus code:
Since this seems wide-spreading to more cases, I ended up downgrading Twig to the lowest required version and now is working fine:
Comment #23
mikelutzd70rr3s - You are on 8.6.10, this issue in core was fixed in 8.6.12. You need to update core. If you were on 8.6.12, you wouldn't be able to downgrade to 1.37 because that version is no longer supported as of 8.6.12.
I'm closing this issue again, as we have not identified any core issues in this thread.
All issues with the %trans% tag have been accounted for either from a custom module or theme overriding core's trans, which is fixed, or by the reporter being on an old version of Drupal < 8.6.12 in which core's trans had not yet been fixed.
Comment #24
guardiola86 commented@jproctor solution worked for me.
Comment #25
dalinThe solution proposed by @jproctor in comment 8 worked for me. Even though I only saw the exception on an admin page, and it was my front-end (emulsify-based) theme that was the problem.
In short:
I also tried someone else's suggestion of downgrading twig/twig, but that didn't work for me. The lowest that I could go was 1.38.2 which still had the problem.
Comment #26
code-brighton commentedI was getting this error after upgrade to Core 8.6.15 from 8.6.10. The solution was found at https://www.drupal.org/project/drupal/issues/3051269 I needed to update twig/twig in my lock file from 1.40.0 to 1.40.1
Comment #27
sararellano commentedI had the same mistake. I have solved it deleting `{% trans %}`. I had this code:
`{% trans %} {{ 'My text'|t }} {% endtrans %} and then some inputs with "name" attribute. I have delete `{% trans %}` and now it works fine.
Comment #28
ressaI was trying to translating strings inside
{% trans %} {% plural count %}Twig tags for Facets Summary with this, and failed:{% trans %}{{ count }} {{ "municipality"|t }}{% plural count %}{{ count }} {{ "municipalities"|t }}{% endtrans %}With Twig variables, I could translate the strings first, and then use them inside
{% trans %}like this: