symfony: [DI] Some Twig extensions work automatically, others don't

Q A
Bug report? no
Feature request? no
BC Break report? no
Symfony version 3.3

In https://github.com/symfony/symfony-demo/pull/562 we’re updating the Symfony Demo app to 3.3.0 RC1 and all the new DI features. During the upgrade I saw this error:

Unknown "localizeddate" filter.

The reason is that I removed the original service definition for the Intl Twig extension:

app.twig.intl_extension:
    public: false
    class:  Twig_Extensions_Extension_Intl
    tags:
        - { name: twig.extension }

If I put the config back, everything works again. I think it’s confusing that “auto-services” work for our own Twig extensions but not for Symfony’s extensions. Is there anything we can do to improve this situation? Thanks

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (13 by maintainers)

Commits related to this issue

Most upvoted comments

It’s one of the bundle I’ve developed 😉 I’ve simply added a twig_extensions.yaml in config > packages > prod! Thanks for your help!

well, in project-level, you still provide some services (using them is not happening in this file). The difference is that you can also provide services for some third-party classes, if these classes don’t have a bundle providing the service. The issue happens when multiple places are trying to provide similar services (Twig does not like multiple registrations of an extension, as it might lead to weird behavior sometimes)