From b058026126609114a5b35e4df4ca05161fd9c1c0 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 18 Nov 2025 07:56:41 +0100 Subject: [PATCH] feat: switch to yaml config format --- .../sitemap/add-custom-sitemap-entries.md | 31 ++++------ .../implementing-your-own-stock-storage.md | 24 +++----- ...stock-information-from-different-source.md | 24 +++----- .../custom-field/add-custom-field.md | 19 ++---- .../data-handling/add-data-translations.md | 35 +++++------ .../flow/add-flow-builder-trigger.md | 18 +++--- .../add-custom-commands.md | 49 ++++++--------- .../plugin-fundamentals/add-custom-service.md | 59 +++++++------------ .../plugin-fundamentals/add-scheduled-task.md | 44 +++++++------- .../dependency-injection.md | 20 ++----- .../storefront/add-cookie-to-manager.md | 24 +++----- 11 files changed, 131 insertions(+), 216 deletions(-) diff --git a/guides/plugins/plugins/content/sitemap/add-custom-sitemap-entries.md b/guides/plugins/plugins/content/sitemap/add-custom-sitemap-entries.md index 437eacc8e..e5d226630 100644 --- a/guides/plugins/plugins/content/sitemap/add-custom-sitemap-entries.md +++ b/guides/plugins/plugins/content/sitemap/add-custom-sitemap-entries.md @@ -168,25 +168,18 @@ class CustomUrlProvider extends AbstractUrlProvider - - -```xml -// /src/Resources/config/services.xml - - - - - - - - - - - - - + + +```yaml +// /src/Resources/config/services.yaml +services: + Swag\BasicExample\Core\Content\Sitemap\Provider\CustomUrlProvider: + arguments: + - '@swag_example.repository' + - '@Doctrine\DBAL\Connection' + - '@router' + tags: + - shopware.sitemap_url_provider ``` diff --git a/guides/plugins/plugins/content/stock/implementing-your-own-stock-storage.md b/guides/plugins/plugins/content/stock/implementing-your-own-stock-storage.md index bab281f2c..a5232e7fb 100644 --- a/guides/plugins/plugins/content/stock/implementing-your-own-stock-storage.md +++ b/guides/plugins/plugins/content/stock/implementing-your-own-stock-storage.md @@ -77,21 +77,15 @@ class StockStorageDecorator extends AbstractStockStorage - - -```xml -// /src/Resources/config/services.xml - - - - - - - - - + + +```yaml +// /src/Resources/config/services.yaml +services: + Swag\Example\Service\StockStorageDecorator: + decorates: Shopware\Core\Content\Product\Stock\StockStorage + arguments: + - '@Swag\Example\Service\StockStorageDecorator.inner' ``` diff --git a/guides/plugins/plugins/content/stock/loading-stock-information-from-different-source.md b/guides/plugins/plugins/content/stock/loading-stock-information-from-different-source.md index 95c89e4ae..04b7d19a7 100644 --- a/guides/plugins/plugins/content/stock/loading-stock-information-from-different-source.md +++ b/guides/plugins/plugins/content/stock/loading-stock-information-from-different-source.md @@ -75,21 +75,15 @@ class StockStorageDecorator extends AbstractStockStorage - - -```xml -// /src/Resources/config/services.xml - - - - - - - - - + + +```yaml +// /src/Resources/config/services.yaml +services: + Swag\Example\Service\StockStorageDecorator: + decorates: Shopware\Core\Content\Product\Stock\StockStorage + arguments: + - '@Swag\Example\Service\StockStorageDecorator.inner' ``` diff --git a/guides/plugins/plugins/framework/custom-field/add-custom-field.md b/guides/plugins/plugins/framework/custom-field/add-custom-field.md index 5d03bcf7e..44b37054a 100644 --- a/guides/plugins/plugins/framework/custom-field/add-custom-field.md +++ b/guides/plugins/plugins/framework/custom-field/add-custom-field.md @@ -216,19 +216,12 @@ So now you've already filled the custom fields of one of your entity instances v Only if you want your custom field to show up in the Administration and to be editable in there, you have to define the custom fields first in a custom field set. For this you have to use the custom fieldset repository, which can be retrieved from the dependency injection container via the `custom_field_set.repository` key and is used like any other repository. -```xml - - - - - - - ... - - - +```yaml +services: + Swag\BasicExample\CustomFieldClass: + arguments: + - '@custom_field_set.repository' + # ... ``` If you need to learn how that is done in full, head to our guide regarding [Writing data](../data-handling/writing-data). diff --git a/guides/plugins/plugins/framework/data-handling/add-data-translations.md b/guides/plugins/plugins/framework/data-handling/add-data-translations.md index 73ada1fd6..b122eaedb 100644 --- a/guides/plugins/plugins/framework/data-handling/add-data-translations.md +++ b/guides/plugins/plugins/framework/data-handling/add-data-translations.md @@ -133,27 +133,20 @@ class ExampleTranslationDefinition extends EntityTranslationDefinition As you can see, we've implemented a `StringField` for the `name` column, the other fields like the `language_id` will be automatically added by the `EntityTranslationDefinition` since they are base fields of it. -All that's left to do now, is to introduce your `ExampleTranslationDefinition` to Shopware by registering your class in your `services.xml` file and by using the `shopware.entity.definition` tag, because Shopware 6 is looking for definitions this way. Note, that we have to register the translation after the entity we want to translate. - -Here's the `services.xml` as it should look like: - -```xml -// /src/Resources/config/services.xml - - - - - - - - - - - - - +All that's left to do now, is to introduce your `ExampleTranslationDefinition` to Shopware by registering your class in your `services.yaml` file and by using the `shopware.entity.definition` tag, because Shopware 6 is looking for definitions this way. Note, that we have to register the translation after the entity we want to translate. + +Here's the `services.yaml` as it should look like: + +```yaml +// /src/Resources/config/services.yaml +services: + Swag\BasicExample\Core\Content\Example\ExampleDefinition: + tags: + - { name: shopware.entity.definition, entity: swag_example } + + Swag\BasicExample\Core\Content\Example\Aggregate\ExampleTranslation\ExampleTranslationDefinition: + tags: + - { name: shopware.entity.definition, entity: swag_example_translation } ``` ### Entity class diff --git a/guides/plugins/plugins/framework/flow/add-flow-builder-trigger.md b/guides/plugins/plugins/framework/flow/add-flow-builder-trigger.md index 4629c278a..abffb2c00 100644 --- a/guides/plugins/plugins/framework/flow/add-flow-builder-trigger.md +++ b/guides/plugins/plugins/framework/flow/add-flow-builder-trigger.md @@ -392,14 +392,16 @@ public static function getSubscribedEvents() } ``` -And remember to register your subscriber to the container at `/src/Resources/config/services.xml` - -```xml -// /src/Resources/config/services.xml - - - - +And remember to register your subscriber to the container at `/src/Resources/config/services.yaml` + +```yaml +// /src/Resources/config/services.yaml +services: + Swag\ExamplePlugin\Core\Checkout\Customer\Subscriber\BusinessEventCollectorSubscriber: + arguments: + - '@Shopware\Core\Framework\Event\BusinessEventCollector' + tags: + - kernel.event_subscriber ``` Well done, you have successfully created your own flow trigger. diff --git a/guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md b/guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md index f7d517cc7..09db768af 100644 --- a/guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md +++ b/guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md @@ -19,7 +19,7 @@ This guide **does not** explain how to create a new plugin for Shopware 6. Head -The main requirement here is to have a `services.xml` file loaded in your plugin. This can be achieved by placing the file into a `Resources/config` directory relative to your plugin's base class location. +The main requirement here is to have a `services.yaml` file loaded in your plugin. This can be achieved by placing the file into a `Resources/config` directory relative to your plugin's base class location. ::: info Refer to this video on custom **[Creating a CLI command](https://www.youtube.com/watch?v=OL_qNVLLyaI)**. Also available on our free online training ["Shopware 6 Backend Development"](https://academy.shopware.com/courses/shopware-6-backend-development-with-jisse-reitsma). @@ -27,35 +27,26 @@ Refer to this video on custom **[Creating a CLI command](https://www.youtube.com ## Registering your command -From here on, everything works exactly like in Symfony itself. Commands are recognised by Shopware, once they're tagged with the `console.command` tag in the [dependency injection](dependency-injection) container. So to register a new command, just add it to your plugin's `services.xml` and specify the `console.command` tag: +From here on, everything works exactly like in Symfony itself. Commands are recognised by Shopware, once they're tagged with the `console.command` tag in the [dependency injection](dependency-injection) container. So to register a new command, just add it to your plugin's `services.yaml` and specify the `console.command` tag: -```html - - +```yaml +services: + # ... - - - - - + Swag\BasicExample\Command\ExampleCommand: + tags: + - console.command + # ... ``` -Here's a full example `services.xml` which registers your custom command: +Here's a full example `services.yaml` which registers your custom command: -```xml -// /src/Resources/config/services.xml - - - - - - - - - - +```yaml +// /src/Resources/config/services.yaml +services: + Swag\BasicExample\Command\ExampleCommand: + tags: + - console.command ``` Your command's class should extend from the `Symfony\Component\Console\Command\Command` class, here's an example: @@ -72,15 +63,9 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Attribute\AsCommand; // Command name -#[AsCommand(name: 'swag-commands:example')] +#[AsCommand(name: 'swag-commands:example', description: 'Does something very special.')] class ExampleCommand extends Command { - // Provides a description, printed out in bin/console - protected function configure(): void - { - $this->setDescription('Does something very special.'); - } - // Actual code executed in the command protected function execute(InputInterface $input, OutputInterface $output): int { diff --git a/guides/plugins/plugins/plugin-fundamentals/add-custom-service.md b/guides/plugins/plugins/plugin-fundamentals/add-custom-service.md index b50af8a6b..106d7e02d 100644 --- a/guides/plugins/plugins/plugin-fundamentals/add-custom-service.md +++ b/guides/plugins/plugins/plugin-fundamentals/add-custom-service.md @@ -18,21 +18,13 @@ Therefore, you can refer to the [Plugin Base Guide](../plugin-base-guide). ## Adding service -For adding a custom service, you need to provide a `services.xml` file in your plugin. -Place a file with name `services.xml` into a directory called `src/Resources/config/`. +For adding a custom service, you need to provide a `services.yaml` file in your plugin. +Place a file with name `services.yaml` into a directory called `src/Resources/config/`. ::: code-group -```xml [PLUGIN_ROOT/src/Resources/config/services.xml] - - - - - - - +```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml] +services: ``` ::: @@ -41,24 +33,21 @@ Now you have two possibilities to add a service to your plugin. ### Using autowire and autoconfigure -Set `autowire` and `autoconfigure` to `true` in your `services.xml` file. +Set `autowire` and `autoconfigure` to `true` in your `services.yaml` file. Symfony will then automatically register your service. Read more about it in the [Symfony docs](https://symfony.com/doc/current/service_container.html#creating-configuring-services-in-the-container). ::: code-group -```xml [PLUGIN_ROOT/src/Resources/config/services.xml] - - - +```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml] +services: + _defaults: + autowire: true + autoconfigure: true - - - - - + Swag\BasicExample\: + resource: '../../' + exclude: '../../{Resources,Migration,*.php}' ``` ::: @@ -73,17 +62,9 @@ Use this option if you want to have more control over your service. ::: code-group -```xml [PLUGIN_ROOT/src/Resources/config/services.xml] - - - - - - - - +```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml] +services: + Swag\BasicExample\Service\ExampleService: ~ ``` ::: @@ -115,11 +96,11 @@ By default, all services in Shopware 6 are marked as _private_. Read more about [private and public services](https://symfony.com/doc/current/service_container.html#public-versus-private-services). ::: -## Alternatives to XML +## Using YAML -Symfony offers two other file formats to define your services: YAML and PHP. -In Shopware, it is also possible to use one of these. -Choose the one that suits you best. +Symfony offers YAML as the recommended format to define your services, as XML is deprecated. +In Shopware, YAML is the preferred format. +You can also use PHP if needed. ## Next steps diff --git a/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task.md b/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task.md index d4a1a6075..e39c96ef4 100644 --- a/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task.md +++ b/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task.md @@ -13,7 +13,7 @@ Quite often one might want to run any type of code on a regular basis, e.g. to c ## Prerequisites -This guide is built upon our [plugin base guide](../plugin-base-guide), but that one is not mandatory. Knowing how the `services.xml` file in a plugin works is also helpful, which will be taught in our guides about [Dependency Injection](dependency-injection) and [Creating a service](add-custom-service). It is shortly explained here as well though, so no worries! +This guide is built upon our [plugin base guide](../plugin-base-guide), but that one is not mandatory. Knowing how the `services.yaml` file in a plugin works is also helpful, which will be taught in our guides about [Dependency Injection](dependency-injection) and [Creating a service](add-custom-service). It is shortly explained here as well though, so no worries! ::: info Refer to this video on **[Adding scheduled tasks](https://www.youtube.com/watch?v=88S9P3x6wYE)**. Also available on our free online training ["Shopware 6 Backend Development"](https://academy.shopware.com/courses/shopware-6-backend-development-with-jisse-reitsma). @@ -21,34 +21,30 @@ Refer to this video on **[Adding scheduled tasks](https://www.youtube.com/watch? ## Registering scheduled task in the DI container -A `ScheduledTask` and its respective `ScheduledTaskHandler` are registered in a plugin's `services.xml`. For it to be found by Shopware 6 automatically, you need to place the `services.xml` file in a `Resources/config/` directory, relative to the location of your plugin's base class. The path could look like this: `/src/Resources/config/services.xml`. - -Here's an example `services.xml` containing a new `ScheduledTask` as well as a new `ScheduledTaskHandler`: - -```xml -// /src/Resources/config/services.xml - - - - - - - - - - - - - +A `ScheduledTask` and its respective `ScheduledTaskHandler` are registered in a plugin's `services.yaml`. For it to be found by Shopware 6 automatically, you need to place the `services.yaml` file in a `Resources/config/` directory, relative to the location of your plugin's base class. The path could look like this: `/src/Resources/config/services.yaml`. + +Here's an example `services.yaml` containing a new `ScheduledTask` as well as a new `ScheduledTaskHandler`: + +```yaml +// /src/Resources/config/services.yaml +services: + Swag\BasicExample\Service\ScheduledTask\ExampleTask: + tags: + - shopware.scheduled.task + + Swag\BasicExample\Service\ScheduledTask\ExampleTaskHandler: + arguments: + - '@scheduled_task.repository' + - '@logger' + tags: + - messenger.message_handler ``` Note the tags required for both the task and its respective handler, `shopware.scheduled.task` and `messenger.message_handler`. Your custom task will now be saved into the database once your plugin is activated. ## ScheduledTask and its handler -As you might have noticed, the `services.xml` file tries to find both the task itself as well as the new task handler in a directory called `Service/ScheduledTask`. This naming is up to you, Shopware 6 decided to use this name though. +As you might have noticed, the `services.yaml` file tries to find both the task itself as well as the new task handler in a directory called `Service/ScheduledTask`. This naming is up to you, Shopware 6 decided to use this name though. Here's the an example `ScheduledTask`: @@ -102,7 +98,7 @@ class ExampleTaskHandler extends ScheduledTaskHandler } ``` -The task handler, `ExampleTaskHandler` as defined previously in your `services.xml`, will be annotated with `AsMessageHandler` handling the `ExampleTask` class. In addition, the `ScheduledTaskHandler` has to extend from the class `Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler`. This also comes with one method that you need to implement first: +The task handler, `ExampleTaskHandler` as defined previously in your `services.yaml`, will be annotated with `AsMessageHandler` handling the `ExampleTask` class. In addition, the `ScheduledTaskHandler` has to extend from the class `Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler`. This also comes with one method that you need to implement first: * `run`: This method is executed once your scheduled task is executed. Do everything, that your task is supposed to do here. In this example, it will just create a new file. diff --git a/guides/plugins/plugins/plugin-fundamentals/dependency-injection.md b/guides/plugins/plugins/plugin-fundamentals/dependency-injection.md index dd42a95c5..7e1ad9e1b 100644 --- a/guides/plugins/plugins/plugin-fundamentals/dependency-injection.md +++ b/guides/plugins/plugins/plugin-fundamentals/dependency-injection.md @@ -59,7 +59,7 @@ class ExampleService ### Using autowire and autoconfigure -If you previously declared `autowire` and `autoconfigure` in your `services.xml` file, you do not need to do anything else. +If you previously declared `autowire` and `autoconfigure` in your `services.yaml` file, you do not need to do anything else. The `SystemConfigService` will be injected into the `ExampleService` automatically. ### Explicit declaration @@ -68,19 +68,11 @@ If you declared the service explicitly, you need to add the `SystemConfigService ::: code-group -```xml [PLUGIN_ROOT/src/Resources/config/services.xml] - - - - - - - - - - +```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml] +services: + Swag\BasicExample\Service\ExampleService: + arguments: + - '@Shopware\Core\System\SystemConfig\SystemConfigService' ``` ::: diff --git a/guides/plugins/plugins/storefront/add-cookie-to-manager.md b/guides/plugins/plugins/storefront/add-cookie-to-manager.md index 7d782d080..150965ca3 100644 --- a/guides/plugins/plugins/storefront/add-cookie-to-manager.md +++ b/guides/plugins/plugins/storefront/add-cookie-to-manager.md @@ -29,22 +29,14 @@ It is recommended to use an event listener if you're listening to a single event ### Registering your event listener -Start with creating the `services.xml` and registering your event listener. - -```xml -// /src/Resources/config/services.xml - - - - - - - - - - +Start with creating the `services.yaml` and registering your event listener. + +```yaml +// /src/Resources/config/services.yaml +services: + PluginName\Listener\CookieListener: + tags: + - { name: kernel.event_listener, event: Shopware\Storefront\Framework\Cookie\CookieGroupsCollectEvent } ``` In the next step we'll create the actual listener class.