From ebc6ed3a9f9ee22cb86eea18cf628b5228d50e12 Mon Sep 17 00:00:00 2001 From: ROBJkE Date: Sat, 2 Aug 2025 16:38:53 +0200 Subject: [PATCH 1/7] feat: decribe how to set mail data via subscriber --- .../plugins/content/mail/add-data-to-mails.md | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 6cb2509cb..669bc85e9 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -91,3 +91,45 @@ Here's the respective example `services.xml`: ``` + +## Adding data via subscriber +You can also add mail data via an event subscriber which is in many cases a suitable solution. So you don't have the overhead by decorating the mail service. Simply crating an event subscriber and listen to the `MailBeforeValidateEvent` event. There you can safly add template data or mail data. +Here is a small example: + +```php +// /src/Subscriber/MyMailSubscriber.php + 'beforeMailValidate' + ]; + } + + public function beforeMailValidate( + MailBeforeValidateEvent $event + ): void { + $context = $event->getContext(); + $data = $event->getData(); + $templateData = $event->getTemplateData(); + + $event->setTemplateData([ + 'key' => 'key', + ]); // Example of set template data + + $event->addTemplateData('key', 'value'); // Example of adding data to the template + } +} +``` \ No newline at end of file From 9e539b264b367340ff71f795f168bf4d9657a0b1 Mon Sep 17 00:00:00 2001 From: ROBJkE Date: Sat, 2 Aug 2025 16:46:37 +0200 Subject: [PATCH 2/7] fix typo --- guides/plugins/plugins/content/mail/add-data-to-mails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 669bc85e9..65fbb3b43 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -93,7 +93,7 @@ Here's the respective example `services.xml`: ``` ## Adding data via subscriber -You can also add mail data via an event subscriber which is in many cases a suitable solution. So you don't have the overhead by decorating the mail service. Simply crating an event subscriber and listen to the `MailBeforeValidateEvent` event. There you can safly add template data or mail data. +In many cases, adding mail data via an event subscriber is a suitable solution. This way, you avoid the overhead of decorating the mail service. Simply create an event subscriber and listen to the `MailBeforeValidateEvent` event. There, you can safely add template or mail data. Here is a small example: ```php From 2e09cec76f396d0d0e6bf847c5ce726663766c71 Mon Sep 17 00:00:00 2001 From: ROBJkE Date: Mon, 11 Aug 2025 16:16:31 +0200 Subject: [PATCH 3/7] add newlines --- guides/plugins/plugins/content/mail/add-data-to-mails.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 65fbb3b43..1b6a2d208 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -93,6 +93,7 @@ Here's the respective example `services.xml`: ``` ## Adding data via subscriber + In many cases, adding mail data via an event subscriber is a suitable solution. This way, you avoid the overhead of decorating the mail service. Simply create an event subscriber and listen to the `MailBeforeValidateEvent` event. There, you can safely add template or mail data. Here is a small example: @@ -132,4 +133,4 @@ class MyMailSubscriber implements EventSubscriberInterface $event->addTemplateData('key', 'value'); // Example of adding data to the template } } -``` \ No newline at end of file +``` From a906d34588cc8e53869bbba99cdd7a6142559f90 Mon Sep 17 00:00:00 2001 From: ROBJkE Date: Fri, 15 Aug 2025 14:47:31 +0200 Subject: [PATCH 4/7] add inline comments, remove setTemplateData() part --- .../plugins/plugins/content/mail/add-data-to-mails.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 1b6a2d208..2d7e348dd 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -110,7 +110,6 @@ use Shopware\Core\Content\MailTemplate\Service\Event\MailBeforeValidateEvent; class MyMailSubscriber implements EventSubscriberInterface { - public function __construct() {} public static function getSubscribedEvents(): array { @@ -123,14 +122,10 @@ class MyMailSubscriber implements EventSubscriberInterface MailBeforeValidateEvent $event ): void { $context = $event->getContext(); - $data = $event->getData(); - $templateData = $event->getTemplateData(); + $data = $event->getData(); // Get mail data + $templateData = $event->getTemplateData(); // Get mail template data - $event->setTemplateData([ - 'key' => 'key', - ]); // Example of set template data - - $event->addTemplateData('key', 'value'); // Example of adding data to the template + $event->addTemplateData('key', 'value'); // Example of adding data to the mail template } } ``` From 12425cdd0f489aa35daf397afe0a9e158753412e Mon Sep 17 00:00:00 2001 From: Micha Date: Tue, 19 Aug 2025 11:10:23 +0200 Subject: [PATCH 5/7] fix: twig-inline-code-and-xml --- .../plugins/content/mail/add-data-to-mails.md | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 2d7e348dd..8641ec4b5 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -27,8 +27,9 @@ To be precise, you have to extend the `send` method, whose last parameter is the So let's do that, here's an example of a decorated mail service: -```php -// /src/Service/AddDataToMails.php +::: code-group + +```php [PLUGIN_ROOT/src/Service/AddDataToMails.php] {{ myCustomData }} to any mail template, it should then print "Example data". You can use any kind of data here, e.g. an array of data. ### Register your decorator @@ -77,8 +80,9 @@ Of course you still have to register the decoration to the service container. Be Here's the respective example `services.xml`: -```xml -// /src/Resources/config/services.xml +::: code-group + +```xml [PLUGIN_ROOT/src/Resources/config/services.xml] ``` +::: + ## Adding data via subscriber In many cases, adding mail data via an event subscriber is a suitable solution. This way, you avoid the overhead of decorating the mail service. Simply create an event subscriber and listen to the `MailBeforeValidateEvent` event. There, you can safely add template or mail data. Here is a small example: -```php -// /src/Subscriber/MyMailSubscriber.php +::: code-group + +```php [PLUGIN_ROOT/src/Subscriber/MyMailSubscriber.php] Date: Tue, 19 Aug 2025 11:20:47 +0200 Subject: [PATCH 6/7] Update guides/plugins/plugins/content/mail/add-data-to-mails.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- guides/plugins/plugins/content/mail/add-data-to-mails.md | 1 - 1 file changed, 1 deletion(-) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 8641ec4b5..5b77c5fbb 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -117,7 +117,6 @@ use Shopware\Core\Content\MailTemplate\Service\Event\MailBeforeValidateEvent; class MyMailSubscriber implements EventSubscriberInterface { - public static function getSubscribedEvents(): array { return [ From 8c1b3a915ff70e93d007744938b2626be4c9d1c2 Mon Sep 17 00:00:00 2001 From: Micha Hobert Date: Tue, 19 Aug 2025 11:20:56 +0200 Subject: [PATCH 7/7] Update guides/plugins/plugins/content/mail/add-data-to-mails.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- guides/plugins/plugins/content/mail/add-data-to-mails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/plugins/plugins/content/mail/add-data-to-mails.md b/guides/plugins/plugins/content/mail/add-data-to-mails.md index 5b77c5fbb..ede6e78e2 100644 --- a/guides/plugins/plugins/content/mail/add-data-to-mails.md +++ b/guides/plugins/plugins/content/mail/add-data-to-mails.md @@ -120,7 +120,7 @@ class MyMailSubscriber implements EventSubscriberInterface public static function getSubscribedEvents(): array { return [ - MailBeforeValidateEvent::class => 'beforeMailValidate' + MailBeforeValidateEvent::class => 'beforeMailValidate', ]; }