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: docs/plugin_extensions/emails.rst
+163Lines changed: 163 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,6 +128,169 @@ This pattern lets you add new per-Email settings and surface them in a Symfony f
128
128
129
129
.. vale off
130
130
131
+
Database-sourced tokens with BuilderTokenHelper
132
+
===============================================
133
+
134
+
.. vale on
135
+
136
+
When your tokens represent database entities like Landing Pages, Assets, or Forms, use the ``BuilderTokenHelper`` to query and format them. This helper handles permission checks, search filtering, and consistent label formatting.
137
+
138
+
Getting the helper
139
+
------------------
140
+
141
+
Inject ``BuilderTokenHelperFactory`` and create a helper for your entity type:
Use ``getFormattedTokens()`` to retrieve tokens with properly formatted labels. This method accepts ``TokenFormatOptions`` to control the label format:
187
+
188
+
.. code-block:: PHP
189
+
190
+
<?php
191
+
192
+
use Mautic\CoreBundle\DTO\TokenFormatOptions;
193
+
use Mautic\CoreBundle\Event\BuilderEvent;
194
+
use Mautic\CoreBundle\Helper\BuilderTokenHelperFactory;
195
+
196
+
public function onBuilderBuild(BuilderEvent $event): void
The ``a:`` prefix indicates a link token. The second parameter is a regular expression pattern to extract the entity ID from the token.
242
+
243
+
Token sorting
244
+
-------------
245
+
246
+
.. vale off
247
+
248
+
Mautic automatically groups tokens in the builder dropdown by type, such as Contact, Company, Owner, Page link, Dynamic Content, Focus Item, Asset, This page, Email. Custom or unrecognized tokens fall into an 'Other' group.
249
+
250
+
.. vale on
251
+
252
+
Within the Contact group, First Name, Last Name, and Title appear first. Tokens then sort alphabetically by label within each group. The ``TokenSorter`` class constants in Mautic core define the authoritative order.
253
+
254
+
Deprecated methods
255
+
------------------
256
+
257
+
.. deprecated:: 7.2
258
+
259
+
Mautic deprecates the following ``BuilderEvent`` methods and removes them in a future version:
260
+
261
+
- ``addTokensFromHelper()`` - Use ``BuilderTokenHelper::getFormattedTokens()`` and ``$event->addTokens()`` instead.
262
+
- ``getTokensFromHelper()`` - Use ``BuilderTokenHelper::getFormattedTokens()`` instead.
263
+
264
+
**Migration example:**
265
+
266
+
.. code-block:: PHP
267
+
268
+
// Before (deprecated):
269
+
public function onEmailBuild(EmailBuilderEvent $event): void
0 commit comments