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.
Problem/Motivation
Our code uses things that are deprecated in Twig 2.x or that we discourage people in contrib and so on from doing.
Proposed resolution
Fix them.
Remaining tasks
Patch
Review
User interface changes
n/a
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#67 | 2600154-rerolling_patch_for_8.6-68.patch | 14.9 KB | Chewie |
#60 | 2600154-3-60.patch | 17.67 KB | alexpott |
#52 | 2600154-2-52.patch | 17.72 KB | alexpott |
Comments
Comment #2
star-szrSomething like this.
Comment #3
star-szrComment #4
star-szrComment #5
joelpittetReviewed the test changes and they all look great.
StringLoader
replaces the removal of theTwig_Loader_String()
.Twig_SimpleFilter
replacesTwig_Filter_Function
generateKey()
method.Thanks @Cottser.
Comment #6
alexpottThis means we are no longer using
use Drupal\Core\Template\TwigExtension;
Also is this really correct - what ware we testing now?
Why do we have to add this? Commenting this out the tests still pass.
Comment #7
joelpittet@alexpott the first thing is showing how a contrib module should be extending twig and that we can extend twig. So to me it's testing how people should be extending Twig, beacuse it's a Test Twig Extension not an "extension" of Drupal's Twig Extension.
I was seeing fails on Scott's computer on the second part of that but only when you ran this with the upgrade. Chalked it up to Unittestible requirements and something funky in 2.x. Did you run it with the upgrade to 2.x?
Comment #8
alexpott@joelpittet nope I didn't - but it is worth understanding why this is necessary for 2.x
Comment #9
joelpittetI'm not sure why those were needed after and not before... kinda a mystery that @Cottser mentioned. I'd actually expect them needed for both if they are used function in the unit tests.
Comment #10
star-szrThank you both!
It's a mystery to me indeed why those changes seem to be needed only for Twig 2.x and not before - like @joelpittet said it seems like if it's a unit test it should be failing to find those procedural functions on HEAD. Someone with more PHPUnit knowledge and experience could probably figure it out.
This fixes #6.1. #6.2 that change could I guess happen in another issue, or maybe in #2591515: Move twig_without() to the TwigExtension where all the other filters are and deprecate because it's similar to that but might also make the scope there a bit weird. Any opinion on these options?
Comment #12
joelpittetFYI I tested it with 2.x again, and @alexpott yes those are definitely needed. Maybe it's just better at shielding itself from DrupalKernal::loadLegacyIncludes() or something?
Also I noticed the date format filter was not working because it's not initialized when the filters are being created so it doesn't think it's callable till runtime.
This fixes that...
Not sure which issue I should add that small shuffle around to?
Comment #13
joelpittet@alexpott and @Cottser the reason it fails is that twig 2.0 removed a feature it had where it would register globals.
"removed the ability to register a global variable after the runtime or the extensions have been initialized"
I'm quite sure that is the reason why.
Comment #15
alexpott@joelpittet hmmm but functions are not global variables.
Comment #16
joelpittetYes right, my guess was due to that was they removed a reflection hunk... Closest thing I could find to why. I put a breakpoint in common.inc and it ran just the same. It could be something else but that looked most probable to me.
Comment #18
alexpottCan someone update the issue summary with steps of how to test with Twig 2.0.x - I wanna find out what is really going on here.
Comment #19
joelpittet@alexpott I'll try in a bit but it's a PITA because of composer dependencies and https://github.com/jcalderonzumba/MinkPhantomJSDriver is requiring ~1.8.
You have to remove it from the core/composer.json, update composer in the root, then update twig in core/composer.json, and update composer in the root again. I don't know composer well enough to know of an easier way.
I'm currently running TravisCI on a forked copy of that to see how it fairs on 2.x as well.
Comment #20
joelpittetOk this gets around the dependency, I forked his repo. Hope that helps for testing.
Just apply this patch and run
composer update
from root.Comment #21
alexpottSo the reason why t() has to be defined is
And the reason why file_create_url() has to be defined is
Twig 2.x has started to check that the second arguments are callable unlike Twig 1.x - I ponder what the performance cost of Twig 2.x is. I think with the t() it is worth adding a method to the TwigExtension that just returns TranslatableMarkup object.
Comment #22
joelpittetHeads up you don't need my patch or fork in #20. My pull request was accepted and the
composer update
works now without it:)Comment #26
joelpittet#10 needs a re-roll for 8.4.x
Comment #27
star-szrQuick attempted reroll, didn't check it very thoroughly so might be broken.
Comment #28
star-szrThis issue might become redundant if #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 is taking care of the test changes. Originally, the plan was to get this in first since the test updates work on Twig 1.x and 2.x.
Comment #31
markhalliwellComment #32
alexpottRerolled and also removed the deprecations that this fixes. I think we should do this regardless of #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 since doing this first helps minimise what that issue has to do.
Comment #33
alexpottThe patch introduces some unnecessary code.
Comment #34
martin107 CreditAttribution: martin107 as a volunteer commentedComment #35
jibranWhy not remove all the deprecations related to twig 2.0?
Comment #36
alexpott@jibran then we need to merge this and #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 together. Let's merge them.
Comment #37
alexpottActually as that issue is changing composer.json let's leave that to do that and this issue should do all the deprecations. Changing composer.json and fixing the depreecations are unrelated activities.
Comment #38
alexpottSo this patch removes all the twig skipped deprecations and removes the legacy group from a load of twig tests where it shouldn't be. Let's see where we are.
Comment #44
Anonymous (not verified) CreditAttribution: Anonymous commentedalexpott credited vaplas.
Comment #45
alexpottCrediting people from #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1
Comment #46
alexpottOne deprecation to fix.
Comment #47
alexpottTrying to remove all unnecessary change to any run-time code.
Comment #49
jibranAll the twig deprecations are gone now code changes look good as well but I'll leave RTBC for someone who is more familiar with theme system.
Comment #50
alexpottRerolled due to changes in \Drupal\Tests\Listeners\DeprecationListenerTrait::getSkippedDeprecations().
Comment #51
joelpittetJust spotted this got some action, here's a review, mostly a big +1, thanks @alexpott!
Why is this change needed? And out of curiosity why is the value NULL in front of the condition? Feels a bit less natural to read, is there an advantage?
+1
+1
Couldn't this stay a StringLoader?
Comment #52
alexpott1. To avoid the deprecation notice in \Twig_Node::__construct()
4. It appears it can. Reverted the changes. Pretty sure they came from #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1
Comment #53
joelpittet1. I couldn't find where the
Twig_Node
deprecation notice would occur due to the previous code but I trust you ran into it and had to make this change.4. Cool, yeah it looks like it did come from there. Thanks for reverting, it looks more straight forward with stringloader.
Comment #54
alexpottSlightly tweaking the issue summary and title to reflect that there are a couple of run-time (non test) changes.
Comment #55
alexpott@joelpittet re #53.1 see
\Twig_Node::__construct()
especially:Comment #57
alexpottBumping to critical given https://twitter.com/fabpot/status/1024222511746166784
Comment #58
joelpittet@alexpott I see now, sorry wasn't looking at the args change in the parent! Thanks for pointing it out again
Comment #60
alexpottRerolled now that #2991080: Remove skipped deprecations no longer triggered by tests has landed.
Comment #62
catchCommitted/pushed to 8.7.x, thanks!
While I agree it's critical to make Drupal 8 compatible with Twig 2 in the same way #2937984: [META] Symfony 4.0 compatibility is critical, this doesn't seem urgent in that there's no indication of Twig 1 support being dropped soon - and not necessarily a way for us to update from Twig 1 to Twig 2 within 8.x either. So leaving in 8.7.x
Comment #63
joelpittet🚀shipped! Thanks
Comment #65
catchComment #66
Gábor HojtsyGiven that this is in #2572605: Make Drupal 8 optionally working with Twig 2, while keeping its dependency on Twig 1 attempts to test an update to Twig 2, but it still fails and needs further modifications. Would be lovely if people could jump over there and help :) Thanks!
Comment #67
Chewie CreditAttribution: Chewie as a volunteer and at Petend for European Commission and European Union Institutions, Agencies and Bodies commentedHere is version of patch for 8.6.x for people which would like to use.