@@ -6,107 +6,6 @@ How to Use Bundle Inheritance to Override Parts of a Bundle
66
77.. caution ::
88
9- Bundle inheritance is deprecated since Symfony 3.4 and will be removed in
10- 4.0.
11-
12- When working with third-party bundles, you'll probably come across a situation
13- where you want to override a file in that third-party bundle with a file
14- in one of your own bundles. Symfony gives you a very convenient way to override
15- things like controllers, templates, and other files in a bundle's
16- ``Resources/ `` directory.
17-
18- For example, suppose that you have installed `FOSUserBundle `_, but you want to
19- override its base ``layout.html.twig `` template, as well as one of its
20- controllers.
21-
22- First, create a new bundle called UserBundle and enable it in your application.
23- Then, register the third-party FOSUserBundle as the "parent" of your bundle::
24-
25- // src/UserBundle/UserBundle.php
26- namespace UserBundle;
27-
28- use Symfony\Component\HttpKernel\Bundle\Bundle;
29-
30- class UserBundle extends Bundle
31- {
32- public function getParent()
33- {
34- return 'FOSUserBundle';
35- }
36- }
37-
38- By making this simple change, you can now override several parts of the FOSUserBundle
39- simply by creating a file with the same name.
40-
41- .. note ::
42-
43- Despite the method name, there is no parent/child relationship between
44- the bundles, it is just a way to extend and override an existing bundle.
45-
46- Overriding Controllers
47- ~~~~~~~~~~~~~~~~~~~~~~
48-
49- Suppose you want to add some functionality to the ``registerAction() `` of a
50- ``RegistrationController `` that lives inside FOSUserBundle. To do so,
51- just create your own ``RegistrationController.php `` file, override the bundle's
52- original method, and change its functionality::
53-
54- // src/UserBundle/Controller/RegistrationController.php
55- namespace UserBundle\Controller;
56-
57- use FOS\UserBundle\Controller\RegistrationController as BaseController;
58-
59- class RegistrationController extends BaseController
60- {
61- public function registerAction()
62- {
63- $response = parent::registerAction();
64-
65- // ... do custom stuff
66- return $response;
67- }
68- }
69-
70- .. tip ::
71-
72- Depending on how severely you need to change the behavior, you might
73- call ``parent::registerAction() `` or completely replace its logic with
74- your own.
75-
76- .. note ::
77-
78- Overriding controllers in this way only works if the bundle refers to
79- the controller using the standard ``FOSUserBundle:Registration:register ``
80- syntax in routes and templates. This is the best practice.
81-
82- Overriding Resources: Templates, Routing, etc
83- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84-
85- Most resources can also be overridden, simply by creating a file in the same
86- location as your parent bundle.
87-
88- For example, it's very common to need to override the FOSUserBundle's
89- ``layout.html.twig `` template so that it uses your application's base layout.
90- Since the file lives at ``Resources/views/layout.html.twig `` in the FOSUserBundle,
91- you can create your own file in the same location of UserBundle. Symfony will
92- ignore the file that lives inside the FOSUserBundle entirely, and use your file
93- instead.
94-
95- The same goes for routing files and some other resources.
96-
97- .. note ::
98-
99- The overriding of resources only works when you refer to resources with
100- the ``@FOSUserBundle/Resources/config/routing/security.xml `` method.
101- You need to use the ``@BundleName `` shortcut when referring to resources
102- so they can be successfully overridden (except templates, which are
103- overridden in a different way, as explained in :doc: `/templating/overriding `).
104-
105- .. caution ::
106-
107- Translation and validation files do not work in the same way as described
108- above. Read ":ref: `override-translations `" if you want to learn how to
109- override translations and see ":ref: `override-validation `" for tricks to
110- override the validation.
111-
112- .. _`FOSUserBundle` : https://github.com/friendsofsymfony/fosuserbundle
9+ Bundle inheritance was removed in Symfony 4.0, but you can
10+ :doc: `override any part of a bundle </bundles/override >` without
11+ using bundle inheritance.
0 commit comments