Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd28f35

Browse files
committed
moved note to relevant section, added info on how to override a parameter and added section about how to add method calls to services
1 parent 93d0c87 commit dd28f35

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

cookbook/bundles/override.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ How to Override any Part of a Bundle
77
This document is a quick reference for how to override different parts of
88
third-party bundles.
99

10-
.. note::
11-
12-
Whenever you are extending a (part of a) bundle, make sure that your bundle
13-
is registered in the kernel **after** the bundle you're trying to override
14-
parts of. Otherwise, your config that is supposed to override bundle
15-
configuration, is instead overridden by it!
16-
1710
Templates
1811
---------
1912

@@ -42,15 +35,24 @@ inheritance. For more information, see :doc:`/cookbook/bundles/inheritance`.
4235
Services & Configuration
4336
------------------------
4437

38+
.. note::
39+
40+
Whenever you are extending a (part of a) bundle, make sure that your bundle
41+
is registered in the kernel **after** the bundle you're trying to override
42+
parts of. Otherwise, your config that is supposed to override bundle
43+
configuration, is instead overridden by it!
44+
4545
In order to completely override a service, just define the service as you would
4646
usual, but making sure the id of the service is identical to the one you are
4747
overriding.
4848

4949
In order to extend a service (e.g. just add a method, but leaving the
5050
dependencies or tags intact), make sure the class name is defined as a parameter
51-
in the service config of the bundle containing the service. Then, in your bundle
52-
you can override the class name by setting the parameter directly in the
53-
container in the Extension class of your bundle:
51+
in the service config of the bundle containing the service. You can then either
52+
set this parameter in your config.yml, or, if you're going to reuse your bundle
53+
and it should always override the class, in your bundle you can override the
54+
class name by setting the parameter directly in the container in the Extension
55+
class of your bundle:
5456

5557
.. code-block:: html+php
5658
<?php
@@ -77,6 +79,10 @@ container in the Extension class of your bundle:
7779
}
7880
}
7981

82+
If you want to do something beyond just overriding a parameter - like adding a
83+
method call - it must be done as a compiler pass. See
84+
`/cookbook/service_container/compiler_passes`
85+
8086
Entities & Entity mapping
8187
-------------------------
8288

0 commit comments

Comments
 (0)