You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/concepts/commands.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,8 @@ class ExportCommand extends Command
66
66
67
67
Now, in order to make this really simple command available in the console, we register it in the services.yml file:
68
68
69
+
This example uses YAML, but other service configuration files are supported. See [Services]({{< relref "/9/modules/concepts/services/" >}}) for more details.
Copy file name to clipboardExpand all lines: modules/concepts/controllers/admin-controllers/_index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,6 +136,8 @@ public function __construct(
136
136
137
137
In PrestaShop 9.0, controllers must be defined as services. You have two main approaches to configure your controller service:
138
138
139
+
The following examples use YAML, but other service configuration files are supported. See [Services]({{< relref "/9/modules/concepts/services/" >}}) for more details.
140
+
139
141
### Option 1: Explicit service configuration with tags
Copy file name to clipboardExpand all lines: modules/concepts/hooks/use-hooks-on-modern-pages.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,7 +152,9 @@ services:
152
152
Note: Since Symfony 4.4, services that are not dependency injected and that are not declared as “public” are removed from the container.
153
153
{{% /notice %}}
154
154
155
-
Prestashop automatically checks if modules have a `config/services.yml` file and will autoload it for you. In order to force Prestashop to parse the file, you need to clear the cache:
155
+
PrestaShop automatically checks module service configuration files and will autoload them for you. This example uses YAML, but other service configuration files are supported. See [Services]({{< relref "/9/modules/concepts/services/" >}}) for more details.
156
+
157
+
In order to force PrestaShop to parse the file, you need to clear the cache:
156
158
157
159
```
158
160
./bin/console cache:clear --no-warmup
@@ -289,4 +291,3 @@ We have used a key for translation, making our own translations available in bac
289
291
And "voila!", the module could be of course improved with so many features, adding filters on export for instance, using the `request` hook parameter and updating the Product repository.
You can also keep YAML files as fallbacks for compatibility with older PrestaShop versions:
131
+
132
+
```text
133
+
yourmodule/
134
+
`-- config/
135
+
|-- services.php
136
+
|-- services-9.2.yml
137
+
|-- services-9.yml
138
+
`-- services.yml
139
+
```
140
+
141
+
When `services.php` exists, it has priority. Otherwise PrestaShop falls back to the most specific YAML file matching
142
+
the current PrestaShop version, then to `services.yml`.
143
+
93
144
This will then allow you to get your service from the Symfony container, like in your modern controllers:
94
145
95
146
```php
@@ -114,7 +165,7 @@ class DemoController extends FrameworkBundleAdminController
114
165
115
166
{{% notice tip %}}
116
167
If you need more details about dependency injection and how services work in the Symfony environment we recommend you to read
117
-
their documentation about the [Service Container](https://symfony.com/doc/4.4/service_container.html).
168
+
their documentation about the [Service Container](https://symfony.com/doc/6.4/service_container.html).
118
169
{{% /notice %}}
119
170
120
171
##### Exclude index.php files when adding wildcard resource
@@ -135,13 +186,13 @@ The container definition can be modified by a module, which enables you to overr
135
186
136
187
This is a mechanism similar to PrestaShop standard overrides, but the main benefit is that the php code stays unmodified. This prevents issues linked to code definition or autoloading failures.
137
188
138
-
As you can read it from the [Symfony documentation](https://symfony.com/doc/current/service_container/service_decoration.html), there are 2 ways to modify an existing service:
189
+
As you can read it from the [Symfony documentation](https://symfony.com/doc/6.4/service_container/service_decoration.html), there are 2 ways to modify an existing service:
139
190
140
191
#### Override the service
141
192
142
193
When you choose to override a service, this means that you _replace the service by another one_. The previous service is not usable anymore. Every other part of the code where this service is used will use the new version.
143
194
144
-
To do it: you declare your new service using the old service name. So if you want to override the service `prestashop.core.b2b.b2b_feature` with your own implementation, you write in `config/services.yml`:
195
+
To do it: you declare your new service using the old service name. So if you want to override the service `prestashop.core.b2b.b2b_feature` with your own implementation, you can write for example in `config/services.yml`:
145
196
146
197
```yml
147
198
prestashop.core.b2b.b2b_feature:
@@ -154,7 +205,7 @@ That's done. The service registered under the name `prestashop.core.b2b.b2b_feat
154
205
155
206
When you choose to decorate a service, this means that you _make everybody use your service but you keep the old service available_. The previous service has been given a new name and can still be used. Every other part of the code where this service was used will use the new version.
156
207
157
-
To do it: you declare your new service using the 'decorates' keyword. So if you want to decorates the service `prestashop.core.b2b.b2b_feature` with my own implementation, you write in `config/services.yml`:
208
+
To do it: you declare your new service using the 'decorates' keyword. So if you want to decorates the service `prestashop.core.b2b.b2b_feature` with my own implementation, you can write for example in `config/services.yml`:
158
209
159
210
```yml
160
211
mymodule.my_own_b2b_feature_service:
@@ -167,7 +218,7 @@ That's done. The service registered under the name `mymodule.my_own_b2b_feature_
167
218
This means that in your container you can access 3 services now:
168
219
169
220
- `mymodule.my_own_b2b_feature_service`your service
170
-
- `prestashop.core.b2b.b2b_feature`is now an alias for `mymodule.my_own_b2b_feature_service` (see [service aliases](https://symfony.com/doc/current/service_container/alias_private.html)) so the other services which rely on it now use your implementation
221
+
- `prestashop.core.b2b.b2b_feature`is now an alias for `mymodule.my_own_b2b_feature_service` (see [service aliases](https://symfony.com/doc/6.4/service_container/alias_private.html)) so the other services which rely on it now use your implementation
171
222
- `mymodule.my_own_b2b_feature_service.inner`is the previous implementation, still available
172
223
173
224
The decoration strategy can be very useful if:
@@ -257,7 +308,7 @@ As you can see, interfaces lay the ground for easy extension and customization,
257
308
258
309
#### Advanced services parameters (_instanceof or interface binding, manual tags)
259
310
260
-
Since {{< minver v=8.1 >}}, [modules autoloaders and service configurations loading are now registered before compiler passes](https://github.com/PrestaShop/PrestaShop/pull/30588). That means that you can now use native Symfony service configuration features in your modules.
311
+
Since {{< minver v=8.1 >}}, [modules autoloaders and service configurations loading are now registered before compiler passes](https://github.com/PrestaShop/PrestaShop/pull/30588). That means that you can now use native Symfony service configuration features in your modules.
261
312
262
313
Those features are:
263
314
@@ -266,7 +317,7 @@ Those features are:
266
317
- [an option to skip the class attribute](https://symfony.com/blog/new-in-symfony-3-3-optional-class-for-named-services)
267
318
- [automatically registering classes found in the specified directories as services](https://symfony.com/blog/new-in-symfony-3-3-psr-4-based-service-discovery)
268
319
269
-
As an example, let's consider a module with the following structure:
320
+
As an example, let's consider a module with the following structure:
This example will tag all classes _instances of_ `TestModule\InstanceofConditionals\Collection\ElementInterface` (`TestModule\InstanceofConditionals\Collection\Element` in our example) with the tag `test_module.instance_of.instance_of_tagged`.
393
+
This example will tag all classes _instances of_ `TestModule\InstanceofConditionals\Collection\ElementInterface` (`TestModule\InstanceofConditionals\Collection\Element` in our example) with the tag `test_module.instance_of.instance_of_tagged`.
343
394
344
395
Then, it will bind all services with a `$element` variable in its constructor with a `test_module.instance_of.instance_of_tagged` service.
345
396
@@ -363,7 +414,7 @@ This example will tag the class `TestModule\InstanceofConditionals\Collection\El
363
414
364
415
Then, it will bind all services with a `$element` variable in its constructor with a `test_module.instance_of.manually_tagged` service.
365
416
366
-
If we wanted to bind only parameter `$element` of class `TestModule\InstanceofConditionals\Collection\Collection` with a `test_module.instance_of.manually_tagged` tag, we would had configured it this way:
417
+
If we wanted to bind only parameter `$element` of class `TestModule\InstanceofConditionals\Collection\Collection` with a `test_module.instance_of.manually_tagged` tag, we would had configured it this way:
367
418
368
419
```yaml
369
420
services:
@@ -378,7 +429,7 @@ services:
378
429
tags: [ test_module.instance_of.manually_tagged ]
379
430
```
380
431
381
-
Explore more configuration features in [the official Symfony documentation](https://symfony.com/doc/4.4/service_container.html#creating-configuring-services-in-the-container).
432
+
Explore more configuration features in [the official Symfony documentation](https://symfony.com/doc/6.4/service_container.html#creating-configuring-services-in-the-container).
382
433
383
434
## Services in Legacy environment
384
435
{{< minver v="1.7.6" title="true" >}}
@@ -393,8 +444,10 @@ container for this environment (`PrestaShop\PrestaShop\Adapter\ContainerBuilder`
393
444
To define your services you need to follow the same principle as Symfony services, but this time you need to place your definition
394
445
files in sub folders:
395
446
396
-
- `config/admin/services.yml`will define the services accessible in the back office (in legacy environment AND Symfony environment)
397
-
- `config/front/services.yml`will define the services accessible in the front office
447
+
- `config/admin/`service configuration files will define the services accessible in the back office (in legacy environment AND Symfony environment)
448
+
- `config/front/`service configuration files will define the services accessible in the front office
449
+
450
+
The service file priority described above also applies in these folders.
398
451
399
452
{{% notice warning %}}
400
453
**Do not use named arguments for front services definition**
@@ -467,12 +520,12 @@ in admin or front. Be careful and always keep in mind in which context/environme
467
520
468
521
Here is a quick summary so that you know where you should define your services:
Copy file name to clipboardExpand all lines: modules/creation/adding-configuration-page-modern.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -114,7 +114,7 @@ This form has only one setting : `config_text`, of type `Symfony\Component\Form\
114
114
115
115
### Register your newly created form type
116
116
117
-
Create a `services.yml` file in `config/`.
117
+
Create a `services.yml` file in `config/`. This example uses YAML, but other service configuration files are supported. See [Services]({{< relref "/9/modules/concepts/services/" >}}) for more details.
0 commit comments