After upgrading from 8.2.7 to 8.3.0 my site throws this error:
The website encountered an unexpected error. Please try again later.
ArgumentCountError: Too few arguments to function Drupal\Core\Template\TwigExtension::__construct(), 1 passed and exactly 4 expected in Drupal\Core\Template\TwigExtension->__construct() (line 68 of core/lib/Drupal/Core/Template/TwigExtension.php).
Drupal\Core\Template\TwigExtension->__construct(Object)
ReflectionClass->newInstanceArgs(Array) (Line: 928)
Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object, 'multi_line.twig_extension') (Line: 468)
Symfony\Component\DependencyInjection\ContainerBuilder->get('multi_line.twig_extension', 1) (Line: 985)
Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Object) (Line: 982)
Symfony\Component\DependencyInjection\ContainerBuilder->resolveServices(Array) (Line: 1142)
Symfony\Component\DependencyInjection\ContainerBuilder->callMethod(Object, Array) (Line: 946)
Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object, 'twig') (Line: 468)
Symfony\Component\DependencyInjection\ContainerBuilder->get('twig') (Line: 158)
Drupal::service('twig') (Line: 56)
twig_render_template('core/themes/classy/templates/layout/html.html.twig', Array) (Line: 384)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 435)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 195)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 139)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 140)
Drupal\Core\Render\Renderer->renderRoot(Array) (Line: 66)
Drupal\Core\Render\BareHtmlPageRenderer->renderBarePage(Array, Object, 'maintenance_page', Array) (Line: 76)
Drupal\Core\ProxyClass\Render\BareHtmlPageRenderer->renderBarePage(Array, Object, 'maintenance_page', Array) (Line: 196)
Drupal\system\Controller\DbUpdateController->handle('info', Object)
call_user_func_array(Array, Array) (Line: 110)
Drupal\Core\Update\UpdateKernel->handleRaw(Object) (Line: 73)
Drupal\Core\Update\UpdateKernel->handle(Object) (Line: 28)
Any idea what could be causing this?
Comments
Any solution ?
Exact same thing here.
Have you found anything ?
Maybe this could help
I had a custom module that provided the template files with a custom Twig extension, and was mentioned in the ArgumentCountError exception message at the equivalent line :
Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object, 'multi_line.twig_extension') (Line: 468)
I added an emtpy constructor method to the Twig extension class mentioned in the error message like so :
public function __construct() {}
... it did the trick.
No sure why this helped but it did.
Does your class providing the 'multi_line.twig_extension' has a constructor ?
Adding new constructor didn't work for me.
We have custom TwigExtension that started to give this error.
(edit, that custom constructor didn't help.)
I have a feeling that something in the declaration of the extension has changed or in the requirements how you're supposed to configure this in the module.services.yml.
Here's my module.services.yml, if I clear this then everything works, apart from the custom twig extension that is.
This did work prior to 8.3 update.
/ Janne
Some progression.
I added another argument to service declaration and got a bit further.
This config gets me to following error:
/ Janne
Found the correct arguments
Found the correct arguments by putting a breakpoint on the first line of TwigExtension->__construct() and looking at the _serviceId attributes.
Note the dots on theme.manager and date.formatter:
So far it seems to work.
arguments
Great find. I was having the same inexplicable issue when trying to create a custom filter. The debug stacktrace showed that a custom filter in the Webform module was actually creating the problem.
Yes, it was a Twig extension
Yes, it was a Twig extension in a custom module that was causing the error.
Thanks for helping out!