- Issue created by @fgm
- ππΊHungary GΓ‘bor Hojtsy Hungary
Updating issue summary with key code excerpts for easier understanding. The Twig logic depends entirely on Twig itself reporting the errors, so not sure why it would not find your plugin. Especially given that you say the module would be installed/enabled.
- ππΊHungary GΓ‘bor Hojtsy Hungary
This is the practical part of our Twig deprecation checking. Looks like the error you are getting is from a Twig SyntaxError exception:
$deprecations = []; set_error_handler(function ($type, $msg, $file, $line) use (&$deprecations) { if (\E_USER_DEPRECATED === $type) { if (preg_match('!([a-zA-Z0-9\_\-\/]+.html\.twig)!', $msg, $file_matches)) { // Caught a Twig syntax based deprecation, record file name and line // number from the message we caught. preg_match('/(\d+).?$/', $msg, $line_matches); $msg = preg_replace('! in (.+)\.twig at line \d+\.!', '.', $msg); $msg .= ' See https://drupal.org/node/3071078.'; $deprecations[] = new DeprecationMessage( $msg, $file_matches[1], $line_matches[1] ?? 0, 'TwigDeprecationAnalyzer' ); } else { // Otherwise record the deprecation from the original caught error. $deprecations[] = new DeprecationMessage( $msg, $file, $line, 'TwigDeprecationAnalyzer' ); } } }); $iterator = new TemplateDirIterator( new TwigRecursiveIterator($extension->getPath()) ); foreach ($iterator as $name => $contents) { try { $this->twigEnvironment->parse($this->twigEnvironment->tokenize(new Source($contents, $name))); } catch (SyntaxError $e) { // Report twig syntax error which stops us from parsing it. $deprecations[] = new DeprecationMessage( 'Twig template ' . $name . ' contains a syntax error and cannot be parsed.', $name, $e->getTemplateLine(), 'TwigDeprecationAnalyzer' ); } } restore_error_handler();
- π«π·France fgm Paris, France
Since you appear to suppose that the module might not be installed, here is a zoomed out copy showing it is indeed installed.
- π«π·France fgm Paris, France
Also, the second screen cap shows that there is indeed no syntax error being reported : the filter is invoked and returns the expected values.
- Status changed to Fixed
4 months ago 7:07pm 20 August 2024 - π«π·France fgm Paris, France
With help from @GΓ‘bor Hojtsy, I found the issue:
- Extensions do not require a
tags: [{ name: twig.extension }]
property on the service defining them to work with core - They do require it to be autoregistered during scanning, and possibly other situations
- The original module and this demo module did not contain the tag on the extension service
So there is this discrepancy between the way things actually work in core, and the way they are scanned, which may or may not be a bug in core or in scanning. But the fix is simple: just tag extensions and they will work in both situations.
- Extensions do not require a
- π«π·France fgm Paris, France
Could have been avoided by some documentation, see #2264047: [meta] Document service definition tags β
Automatically closed - issue fixed for 2 weeks with no activity.