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
@@ -63,22 +64,25 @@ class AddDataToMails extends AbstractMailService
63
64
}
64
65
```
65
66
67
+
:::
68
+
66
69
If you don't recognise the decoration pattern used here, make sure to have a look at our guide about [decorations](../../plugin-fundamentals/adjusting-service).
67
70
68
71
As always, we're passing in the original `MailService` as a constructor parameter, so we can return it in the `getDecorated` method, as well as use the original `send` method after having adjusted the `$templateData`.
69
72
70
73
In this example, we're adding `myCustomData` to the `$templateData`, so that one should be available then.
71
74
72
-
If we add `{{ 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.
75
+
If we add <codev-pre>{{ myCustomData }}</code> to any mail template, it should then print "Example data". You can use any kind of data here, e.g. an array of data.
73
76
74
77
### Register your decorator
75
78
76
79
Of course you still have to register the decoration to the service container. Beware of the `decorates` attribute of our service.
@@ -91,3 +95,45 @@ Here's the respective example `services.xml`:
91
95
</services>
92
96
</container>
93
97
```
98
+
99
+
:::
100
+
101
+
## Adding data via subscriber
102
+
103
+
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.
0 commit comments