Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,18 @@ class CustomUrlProvider extends AbstractUrlProvider

</Tab>

<Tab title="services.xml">

```xml
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Core\Content\Sitemap\Provider\CustomUrlProvider" >
<argument type="service" id="swag_example.repository" />
<argument type="service" id="Doctrine\DBAL\Connection"/>
<argument type="service" id="router"/>

<tag name="shopware.sitemap_url_provider" />
</service>
</services>
</container>
<Tab title="services.yaml">

```yaml
// <plugin root>/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
```

</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,15 @@ class StockStorageDecorator extends AbstractStockStorage

</Tab>

<Tab title="services.xml">

```xml
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\Example\Service\StockStorageDecorator" decorates="Shopware\Core\Content\Product\Stock\StockStorage">
<argument type="service" id="Swag\Example\Service\StockStorageDecorator.inner" />
</service>
</services>
</container>
<Tab title="services.yaml">

```yaml
// <plugin root>/src/Resources/config/services.yaml
services:
Swag\Example\Service\StockStorageDecorator:
decorates: Shopware\Core\Content\Product\Stock\StockStorage
arguments:
- '@Swag\Example\Service\StockStorageDecorator.inner'
```

</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,15 @@ class StockStorageDecorator extends AbstractStockStorage

</Tab>

<Tab title="services.xml">

```xml
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\Example\Service\StockStorageDecorator" decorates="Shopware\Core\Content\Product\Stock\StockStorage">
<argument type="service" id="Swag\Example\Service\StockStorageDecorator.inner" />
</service>
</services>
</container>
<Tab title="services.yaml">

```yaml
// <plugin root>/src/Resources/config/services.yaml
services:
Swag\Example\Service\StockStorageDecorator:
decorates: Shopware\Core\Content\Product\Stock\StockStorage
arguments:
- '@Swag\Example\Service\StockStorageDecorator.inner'
```

</Tab>
Expand Down
19 changes: 6 additions & 13 deletions guides/plugins/plugins/framework/custom-field/add-custom-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\CustomFieldClass">
<argument type="service" id="custom_field_set.repository"/>
...
</service>
</services>
</container>
```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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Core\Content\Example\ExampleDefinition">
<tag name="shopware.entity.definition" entity="swag_example" />
</service>

<service id="Swag\BasicExample\Core\Content\Example\Aggregate\ExampleTranslation\ExampleTranslationDefinition">
<tag name="shopware.entity.definition" entity="swag_example_translation" />
</service>
</services>
</container>
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
// <plugin root>/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
Expand Down
18 changes: 10 additions & 8 deletions guides/plugins/plugins/framework/flow/add-flow-builder-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,16 @@ public static function getSubscribedEvents()
}
```

And remember to register your subscriber to the container at `<plugin root>/src/Resources/config/services.xml`

```xml
// <plugin root>/src/Resources/config/services.xml
<service id="Swag\ExamplePlugin\Core\Checkout\Customer\Subscriber\BusinessEventCollectorSubscriber">
<argument type="service" id="Shopware\Core\Framework\Event\BusinessEventCollector"/>
<tag name="kernel.event_subscriber"/>
</service>
And remember to register your subscriber to the container at `<plugin root>/src/Resources/config/services.yaml`

```yaml
// <plugin root>/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.
Expand Down
49 changes: 17 additions & 32 deletions guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,34 @@

<PageRef page="../plugin-base-guide" />

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).
:::

## 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
<services>
<!-- ... -->
```yaml
services:
# ...

<service id="Swag\BasicExample\Command\ExampleCommand">
<tag name="console.command"/>
</service>
</services>
<!-- ... -->
Swag\BasicExample\Command\ExampleCommand:
tags:
- console.command

Check warning on line 38 in guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md#L38

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Command`, ` command` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md:38:16: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Command`, ` command`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING
# ...
```

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
// <plugin root>/src/Resources/config/services.xml
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Command\ExampleCommand">
<tag name="console.command"/>
</service>
</services>
</container>
```yaml
// <plugin root>/src/Resources/config/services.yaml
services:
Swag\BasicExample\Command\ExampleCommand:
tags:
- console.command

Check warning on line 49 in guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md

View workflow job for this annotation

GitHub Actions / LanguageTool

[LanguageTool] guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md#L49

If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Command`, ` command` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
Raw output
guides/plugins/plugins/plugin-fundamentals/add-custom-commands.md:49:16: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1])
 Suggestions: ` Command`, ` command`
 Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1
 Category: CASING
```

Your command's class should extend from the `Symfony\Component\Console\Command\Command` class, here's an example:
Expand All @@ -72,15 +63,9 @@
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
{
Expand Down
59 changes: 20 additions & 39 deletions guides/plugins/plugins/plugin-fundamentals/add-custom-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
</services>
</container>
```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml]
services:
```

:::
Expand All @@ -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]
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml]
services:
_defaults:
autowire: true
autoconfigure: true

<services>
<defaults autowire="true" autoconfigure="true"/>
<prototype namespace="Swag\BasicExample\" resource="../../" exclude="../../{Resources,Migration,*.php}"/>
</services>
</container>
Swag\BasicExample\:
resource: '../../'
exclude: '../../{Resources,Migration,*.php}'
```

:::
Expand All @@ -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]
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Swag\BasicExample\Service\ExampleService"/>
</services>
</container>
```yaml [PLUGIN_ROOT/src/Resources/config/services.yaml]
services:
Swag\BasicExample\Service\ExampleService: ~
```

:::
Expand Down Expand Up @@ -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

Expand Down
Loading