Fix Twig 3 deprecations

Created on 10 September 2024, 2 months ago
Updated 21 September 2024, about 2 months ago

Problem/Motivation

Following ๐Ÿ“Œ twig/twig 3.11.0 introduces (for Drupal) breaking changes Needs work and ๐Ÿ“Œ twig/twig has a possible sandbox bypass RTBC there are several Twig deprecations that are skipped for now, we need to resolve these so when Twig 4 is released we can upgrade cleanly:

%Since twig/twig 3.11: Changing the value of a "filter" node in a NodeVisitor class is not supported anymore.%




%Since twig/twig 3.12: Getting node "filter" on a "Twig\\Node\\Expression\\FilterExpression" class is deprecated.%
%Since twig/twig 3.12: Getting node "filter" on a "Twig\\Node\\Expression\\Filter\\DefaultFilter" class is deprecated.%
%Since twig/twig 3.12: Getting node "filter" on a "Twig\\Node\\Expression\\Filter\\RawFilter" class is deprecated.%


Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Needs review

Version

11.0 ๐Ÿ”ฅ

Component
Themeย  โ†’

Last updated about 21 hours ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @longwave
  • First commit to issue fork.
  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    finnsky โ†’ changed the visibility of the branch 3473440-fix-twig-3 to hidden.

  • Merge request !9543test spaceless - #3473440 โ†’ (Open) created by finnsky
  • Pipeline finished with Failed
    about 2 months ago
    Total: 521s
    #287225
  • Pipeline finished with Failed
    about 2 months ago
    Total: 351s
    #287279
  • Pipeline finished with Failed
    about 2 months ago
    Total: 143s
    #287309
  • Pipeline finished with Failed
    about 2 months ago
    Total: 455s
    #287324
  • Pipeline finished with Failed
    about 2 months ago
    Total: 968s
    #287350
  • Pipeline finished with Failed
    about 2 months ago
    #287394
  • Pipeline finished with Failed
    about 2 months ago
    Total: 399s
    #287398
  • Pipeline finished with Failed
    about 2 months ago
    Total: 425s
    #287404
  • Pipeline finished with Running
    about 2 months ago
    #287413
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 678s
    #287430
  • Pipeline finished with Failed
    about 2 months ago
    Total: 330s
    #287444
  • Pipeline finished with Failed
    about 2 months ago
    Total: 323s
    #287452
  • Pipeline finished with Failed
    about 2 months ago
    Total: 320s
    #287458
  • Pipeline finished with Failed
    about 2 months ago
    Total: 315s
    #287476
  • Pipeline finished with Failed
    about 2 months ago
    Total: 373s
    #287500
  • Pipeline finished with Failed
    about 2 months ago
    Total: 434s
    #287516
  • Pipeline finished with Failed
    about 2 months ago
    Total: 374s
    #287520
  • Pipeline finished with Failed
    about 2 months ago
    Total: 763s
    #287566
  • Pipeline finished with Failed
    about 2 months ago
    #287583
  • Pipeline finished with Failed
    about 2 months ago
    Total: 366s
    #287605
  • Pipeline finished with Failed
    about 2 months ago
    Total: 1052s
    #287616
  • Pipeline finished with Failed
    about 2 months ago
    Total: 474s
    #287643
  • Pipeline finished with Failed
    about 2 months ago
    Total: 374s
    #287649
  • Pipeline finished with Failed
    about 2 months ago
    Total: 723s
    #287667
  • Status changed to Needs work about 2 months ago
  • Pipeline finished with Failed
    about 2 months ago
    Total: 504s
    #287888
  • Pipeline finished with Failed
    about 2 months ago
    #287903
  • Pipeline finished with Failed
    about 2 months ago
    Total: 466s
    #287915
  • Pipeline finished with Failed
    about 2 months ago
    Total: 484s
    #287932
  • Pipeline finished with Failed
    about 2 months ago
    Total: 426s
    #287941
  • Pipeline finished with Failed
    about 2 months ago
    Total: 139s
    #287948
  • Pipeline finished with Failed
    about 2 months ago
    Total: 630s
    #287956
  • Pipeline finished with Failed
    about 2 months ago
    Total: 418s
    #287961
  • Pipeline finished with Failed
    about 2 months ago
    Total: 397s
    #287983
  • Pipeline finished with Failed
    about 2 months ago
    Total: 398s
    #287997
  • Pipeline finished with Success
    about 2 months ago
    Total: 839s
    #288009
  • Status changed to Needs review about 2 months ago
  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    Spaceless. Seems easier one from this bundle rewritten

    We can remove it without any problems and get better perfomance
    https://github.com/twigphp/Twig/pull/4236
    https://github.com/twigphp/Twig/pull/4308

    Probably every deprecation thing requires own subticket. Not sure. I gonna continue here to have full picture.
    Sending for review to understand if approach is correct.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 392s
    #288114
  • Pipeline finished with Failed
    about 2 months ago
    Total: 127s
    #288115
  • Pipeline finished with Success
    about 2 months ago
    Total: 852s
    #288130
  • Pipeline finished with Success
    about 2 months ago
    Total: 506s
    #288179
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 66s
    #288189
  • Pipeline finished with Success
    about 2 months ago
    Total: 427s
    #288192
  • Merge request !9556The "tag" constructor argument - #3473440 โ†’ (Open) created by finnsky
  • Pipeline finished with Success
    about 2 months ago
    Total: 373s
    #288223
  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    So we have 4(5) types of deprecations

    1. "Not passing an instance of "TwigFunction" when creating a "XXX" function"

    Fixed here in the test-passing-function branch. Can be moved to a separate task.

    2. "The "tag" constructor argument"

    Also fixed here.

    3. "spaceless is deprecated"

    Fixed for tests here. Also fixed tests.

    4 and 5 are related to modifications of the default escape filter using drupal_escape

    https://twig.symfony.com/doc/3.x/filters/escape.html#custom-escapers
    it says here that
    "Built-in escapers cannot be overridden mainly because they should be considered as the final implementation and also for better performance."

    The last point definitely deserves a separate task. All the rest can be merged here or in their subtasks

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands bbrala Netherlands

    Just so you know.

    This complely broke upgrade status and the update bot. Since we now ship deprecations with core. The d11 readiness dashboard showed like +200k errors suddenly and we eventually tracked it back here.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    Gonna check that last deprecations type here.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    Should ๐Ÿ“Œ Fix "Twig\Node\Expression\FilterExpression" deprecation introduced in twig/twig 3.12.0 Active be directly solved in this issue or remain in its own?

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    @gรกbor hojtsy

    It's hard to say now. In the current task (which should later become meta) I consider all deprecations at once and globally. Several are already ready to receive their subtask and be merged.

    As for the task that you linked, I think it has the wrong name. We can't just rewrite the functions there. But consider how drupal_escape and trans work in general. And add it as required by the modern version of Twig. This is currently in progress.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    There are four child issues now, one with its own MR, the three MRs from here need moving to their individual issues - but I think that covers all the newly added deprecations.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    I would say 5 issues but not sure yet ;) As i said better to review also how `trans` and `drupal_escape` works

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    @finnsky ๐Ÿ“Œ Fix "Twig\Node\Expression\FilterExpression" deprecation introduced in twig/twig 3.12.0 Active is RTBC and should fix both drupal_escape and trans.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    Imo we shouldn't just `fix deprecation message` here. But fix deprecations deeper, with research of new twig extending style. This issue is RTBC of course. But - can we do it better? Idk yet.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    finnsky โ†’ changed the visibility of the branch 3473440-twig-deprecations to hidden.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    finnsky โ†’ changed the visibility of the branch test-pasing-function to hidden.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    finnsky โ†’ changed the visibility of the branch test-tag-constructor-argument to hidden.

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands bbrala Netherlands

    While reviewing the child issues i concluded we might need a change record here (or on the twig update issue?).

    Contrib will want to know how to fix these errors, having a guideline on where to find the core fixes will help a lot.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    Imo we shouldn't just `fix deprecation message` here. But fix deprecations deeper, with research of new twig extending style. This issue is RTBC of course. But - can we do it better? Idk yet.

    I think it would be great to have a "good enough" solution ASAP, and then spend any time to fix it even better later. Because these deprecated API uses produce errors with most runs of Upgrade Status on all contrib projects and people can't do anything about it. When we ran Project Status on all contrib modules, these produced 190 thousand twig deprecacted API calls detected across all of Drupal 10 contrib :) This also means that none of those are getting project update bot patches/MRs because they have these unsolvable issues. So a quick solution would be important to unblock the rest of the ecosystem / tooling, then a better solution is not out of question :)

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Gรกbor Hojtsy Hungary

    These were the top errors found in contrib by Project Analysis:

    • 177 765 times (in 1324 projects): Since twig/twig 3.12: Getting node "filter" on a "Twig\Node\Expression\FilterExpression" class is deprecated.
    • 10734 times (in 641 projects): Since twig/twig 3.12: Not passing an instance of "TwigFunction" when creating a "render_var" function of type "Twig\Node\Expression\FunctionExpression" is deprecated.
    • 1080 times (in 209 projects): Since twig/twig 3.12: The "tag" constructor argument of the "Drupal\Core\Template\TwigNodeTrans" class is deprecated and ignored (check which TokenParser class set it to "trans"), the tag is now automatically set by the Parser when needed.
    • 1100 times (in 274 projects): Since twig/twig 3.12: Getting node "filter" on a "Twig\Node\Expression\Filter\RawFilter" class is deprecated.
    • 864 times (in 121 projects): Since twig/twig 3.12: Getting node "filter" on a "Twig\Node\Expression\Filter\DefaultFilter" class is deprecated.
    • 512 times (in 147 projects): Since twig/twig 3.12: Twig Filter "spaceless" is deprecated. See https://drupal.org/node/3071078.

    Are these all being resolved in the children? :)

    Also these two were found in one project each, not a priority IMHO:

    • Since twig/twig 3.12: Character """ at position 2 should not be escaped; the "\ character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character." in formatage_models 4.x-dev
    • Since twig/twig 3.12: Character "T" at position 7 should not be escaped; the "\ character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character." in festeva 1.0.x-dev
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands bbrala Netherlands

    Yeah all being handled in the children.

  • ๐Ÿ‡ท๐Ÿ‡ธSerbia finnsky

    yep. now all deprecations covered
    not sure is this

    "good enough" solution ASAP

    but at least

    solution ASAP

    :)

  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands bbrala Netherlands

    Only the spaceless deprecation fix needs work, 2 are merged, 1 is RTBC. Almost there ^^

Production build 0.71.5 2024