Fabien Potencier
Contributed by Fabien Potencier in #24160

One of the biggest changes of the upcoming Symfony 4 version is the removal of bundles to manage the application code. Bundles will still exist as third-party plugins installed in vendor/, but your own code will live by default in the src/ directory and it will use plain PHP namespaces instead of bundles.

In Symfony 3.4 we worked towards simplifying bundles even more. That's why we deprecated bundle inheritance and we'll remove it in Symfony 4.0. This inheritance mechanism was traditionally used to override some templates, controllers and other elements of third-party bundles. In Symfony 4.0 you'll need to use alternative solutions to override those elements:

  • Controllers: define a route with the same path as the controller you want to override and implement your own logic.
  • Templates: use the common template overriding mechanism with the traditional app/Resources/<BundleName>/views/<templateName>.html.twig dir or the new templates/bundles/<BundleName>/<templateName>.html.twig dir on Symfony 3.4 and higher; you can also use Twig namespaces to define new templates under the same namespace as the bundle you want to customize.
  • Routing: don't load the bundle routes or apply the same technique as controllers.
  • Services and Configuration: use compiler passes or service decoration.
  • Entities: not possible unless the bundle provides a mapped superclass.
  • Forms: use form extensions.
  • Validation: not possible unless the bundle provides validation groups.
  • Translations: not related to bundle inheritance; just override the right translation domain.
Published in #Living on the edge