phpsymfonyinterfacetwigsonata

sonata/twig error after symfony update 2.6 to 3.4


I'm updating a project from sf2.6(php5.6) to sf3.4(php7.1)... its going well but now I'm stuck with an error I can't figure out how to fix it.

Error output: PHP message: PHP Fatal error: Uncaught Symfony\\Component\\Debug\\Exception\\FatalThrowableError: Type error: Argument 2 passed to Sonata\\FormatterBundle\\Formatter\\Pool::add() must implement interface Sonata\\FormatterBundle\\Formatter\\FormatterInterface, boolean given, called in /var/www/var/cache/dev/ContainerMklcxqq/appDevDebugProjectContainer.php on line 4924 in /var/www/vendor/sonata-project/formatter-bundle/src/Formatter/Pool.php:43\nStack trace:\n#0 /var/www/var/cache/dev/ContainerMklcxqq/appDevDebugProjectContainer.php(4924): Sonata\\FormatterBundle\\Formatter\\Pool->add('twig', true, NULL)\n#1 /var/www/var/cache/dev/ContainerMklcxqq/appDevDebugProjectContainer.php(3475): ContainerMklcxqq\\appDevDebugProjectContainer->getSonata_Formatter_PoolService()\n#2 /var/www/var/cache/dev/ContainerMklcxqq/getAssetic_AssetManagerService.php(8): ContainerMklcxqq\\appDevDebugProjectContainer->getTwigService()\n#3 /var/www/var/cache/dev/ContainerMklcxqq/appDevDebugProjectContainer.php(1349): require('/var/www/var/ca...')\n#4 /v...\n'

If I check the mentioned line (4924) in the container I find:

$instance->add('twig', ${($_ = isset($this- >services['sonata.formatter.text.twigengine']) ? $this- 
>services['sonata.formatter.text.twigengine'] : $this- 
>getSonata_Formatter_Text_TwigengineService()) && false ?: '_'}, NULL);

When I check the actual service with "bin/console debug:container sonata.formatter.text.twigengine" I get the following, which is good, I guess:

Information for Service "sonata.formatter.text.twigengine"
==========================================================

 ---------------- ------------------------------------------------
  Option           Value
 ---------------- ------------------------------------------------
  Service ID       sonata.formatter.text.twigengine
  Class            Sonata\FormatterBundle\Formatter\TwigFormatter
  Tags             sonata.text.formatter
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
 ---------------- ------------------------------------------------

And finally, I checked the actual TwigFormatter class, which leads to this post:

final class TwigFormatter implements FormatterInterface

How is this error possible and am I supposed to fix this or is any package update needed? I'm using the newest version of the sonata-project/formatter-bundle and also the newest version of twig/twig.

Help and explanation are much appreciated. Thanks guys.


Solution

  • This bug comes from Symfony, see BUG: FormatterBundle\Formatter\Pool::add() must implement interface then [DI] Error on dumped container for inlined services

    You'll have to wait for this fix to be merged, or if you're a player, apply it yourself.