APY / APYBreadcrumbTrailBundle

Generate a dynamic Twig breadcrumbs trail via Annotations, PHP Attributes or PHP methods.
80 stars 31 forks source link

Setter injection setTemplate never called => null template var instead of string #56

Closed pierre-kubica closed 2 years ago

pierre-kubica commented 3 years ago

Hi everyone!

I simply installed the bundle but had this error:

Argument 1 passed to Twig\Environment::getTemplateClass() must be of the type string, null given, called in /var/www/election/vendor/twig/twig/src/Environment.php on line 309

In Resources/config/services.xml the setter injection should set the template property in APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail with the default template. The apy_breadcrumb_trail.template is well defined (checked with bin/console debug:container --parameters). I xdebugged it and the setter is never called.

I suspect the autowire="true" option to be part of the problem because I tried to set autowire="false" on the apy_breadcrumb_trail service definition only and debugging that service with bin/console debug:container APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail show the service is autowired.

I checked other bundle with setter injection like the standard symfony/twig-bundle and its setters are well called (but that bundle doesn't use autowiring).

My symfony version: 5.0.11 (so I'm stuck with the last version 1.6 of this bundle).

I read that you test the updates in other closed issue so maybe I got something wrong.

Digivia commented 3 years ago

Hi @Kaplan1984, For now (in waiting a better solution) you can solve the problem by adding in your config/services.yaml file:

APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail:
        calls:
            - setTemplate: ['%apy_breadcrumb_trail.template%']

It will work.

rvanlaak commented 2 years ago

The default value of template should be set to 'APYBreadcrumbTrailBundle::breadcrumbtrail.html.twig' according to Configuration.php, so can you elaborate on whether you overwrote your config with something like below?

apy_breadcrumb_trail:
    template: ~
rvanlaak commented 2 years ago

After installing this bundle on a clean Symfony 5.3 install, I was not able to reproduce this issue.

A possible related fix has been made to the Twig template value in3bd29a8d26c9396f4b87c607012f43fd3ade7b44 which was released in v1.7.0-beta.2.

Am going to close this issue for now, but let me know if you are able to reproduce your issue.