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/plugins/config.rst
+201-1Lines changed: 201 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ Mautic recognizes the Plugin through the general config options.
22
22
23
23
.. list-table::
24
24
:header-rows: 1
25
+
:widths: 15 15 40
25
26
26
27
* - Key
27
28
- Type
@@ -99,6 +100,7 @@ The following firewalls are available to routes.
99
100
100
101
.. list-table::
101
102
:header-rows: 1
103
+
:widths: 15 20 65
102
104
103
105
* - Key
104
106
- URL prefix
@@ -127,8 +129,11 @@ Route definitions
127
129
128
130
Route definitions define the route's method, path, controller, parameters, and others defined below.
129
131
132
+
133
+
130
134
.. list-table::
131
135
:header-rows: 1
136
+
:widths: 28 20 25 60
132
137
133
138
* - Key
134
139
- Is required?
@@ -170,6 +175,7 @@ Mautic defaults the following route definitions if not declared otherwise by the
170
175
171
176
.. list-table::
172
177
:header-rows: 1
178
+
:widths: 15 20 50
173
179
174
180
* - Parameter
175
181
- Default value
@@ -290,6 +296,7 @@ There are currently four menus built into Mautic.
290
296
291
297
.. list-table::
292
298
:header-rows: 1
299
+
:widths: 25 50
293
300
294
301
* - Key
295
302
- Description
@@ -321,6 +328,7 @@ Key each item with its respective :ref:`language string key<plugins/translations
321
328
322
329
.. list-table::
323
330
:header-rows: 1
331
+
:widths: 25 15 25 50
324
332
325
333
* - Key
326
334
- Is required?
@@ -489,6 +497,7 @@ For convenience, Mautic auto-tags services defined within specific keys.
489
497
490
498
.. list-table::
491
499
:header-rows: 1
500
+
:widths: 15 15 50
492
501
493
502
* - Key
494
503
- Tag
@@ -522,6 +531,7 @@ Key each service with a unique name to all of Mautic, including other Plugins.
522
531
523
532
.. list-table::
524
533
:header-rows: 1
534
+
:widths: 25 17 15 50
525
535
526
536
* - Key
527
537
- Is required?
@@ -605,6 +615,7 @@ Mautic uses the follow tags to register services as described below.
605
615
606
616
.. list-table::
607
617
:header-rows: 1
618
+
:widths: 35 27 50
608
619
609
620
* - Tag
610
621
- Supported tag arguments
@@ -626,6 +637,7 @@ Mautic uses the follow tags to register services as described below.
626
637
627
638
.. list-table::
628
639
:header-rows: 1
640
+
:widths: 25 15 50
629
641
630
642
* - Tag
631
643
- Supported tag arguments
@@ -638,6 +650,7 @@ Mautic uses the follow tags to register services as described below.
638
650
639
651
.. list-table::
640
652
:header-rows: 1
653
+
:widths: 40 20 50
641
654
642
655
* - Tag
643
656
- Supported tag arguments
@@ -699,4 +712,191 @@ Configure parameters that are consumable through Mautic's ``CoreParameterHelper`
699
712
700
713
.. note:: The default value must match the value's type for Mautic to typecast and transform appropriately. For example, if there isn't a specific default value to declare, define an empty array, ``[]``, for an array type; zero, ``0``, for an integer type; ``TRUE`` or ``FALSE`` for boolean types; and so forth. Services leveraging parameters should accept and handle ``NULL`` for integer and string types, excluding ``0``.
701
714
702
-
.. note:: Parameters aren't exposed to the UI by default. See :ref:`components/config:Configuration` for more information.
715
+
.. note:: Parameters aren't exposed to the UI by default. See :ref:`components/config:Configuration` for more information.
716
+
717
+
718
+
Custom config parameters
719
+
************************
720
+
721
+
You can define custom configuration parameters in your Plugin to support configurable features, such as enabling or disabling functions.
722
+
723
+
Mautic Plugins allow you to define these parameters for use within your Plugin’s code. Store these parameters in ``config/local.php``, and define their default values in the Plugin’s own config file to ensure stability and avoid errors.
724
+
725
+
To avoid errors during cache compilation or when accessing parameters directly from the container without checking for their existence, always define custom parameters in the :ref:`plugins/config:Parameters config items`. This guarantees that the parameter exists and has a fallback value.
726
+
727
+
To add these configuration options in Mautic's configuration section, you’ll need:
728
+
729
+
- An :doc:`event subscriber </plugins/event_listeners>` to register the configuration.
730
+
- A :doc:`Form type </components/forms>` that defines the fields.
731
+
- A specific view for rendering the form.
732
+
733
+
.. note::
734
+
735
+
To translate the Plugin’s tab label in the configuration form, include a translation key like ``mautic.config.tab.helloworld_config`` in the Plugin’s ``messages.ini`` file. Replace ``helloworld_config`` with the ``formAlias`` used when registering the form in the event subscriber.
736
+
737
+
738
+
Config event subscriber
739
+
=======================
740
+
741
+
This allows Plugins to interact with Mautic's configuration events. It listens to two important events: ``ConfigEvents::CONFIG_ON_GENERATE`` and ``ConfigEvents::CONFIG_PRE_SAVE``.
742
+
743
+
The following code example shows how a Plugin structures its event subscriber.
The event subscriber listens to the following events:
799
+
800
+
- ``ConfigEvents::CONFIG_ON_GENERATE``:
801
+
Mautic dispatches this event when it builds the configuration form. This allows the Plugin to inject its own tab and configuration options.
802
+
803
+
- ``ConfigEvents::CONFIG_PRE_SAVE``:
804
+
Mautic triggers this event before it renders the form values and saves them to the ``local.php`` file. This allows the Plugin to clean up or modify the data before writing it to ``local.php``.
805
+
806
+
Generate plugin configuration
807
+
-----------------------------
808
+
.. vale on
809
+
To register Plugin’s configuration details during the ``ConfigEvents::CONFIG_ON_GENERATE event``, call the ``addForm()`` method on the ``ConfigBuilderEvent`` object. The method expects an array with the following elements:
810
+
811
+
.. list-table::
812
+
:header-rows: 1
813
+
:widths: 15 50
814
+
815
+
* - Key
816
+
- Description
817
+
* - ``formAlias``
818
+
- The alias of the form type class that defines the expected form elements.
819
+
* - ``formTheme``
820
+
- The view that formats the configuration form elements, for example, ``HelloWorldBundle:FormTheme\Config``.
821
+
* - ``parameters``
822
+
- An array of custom configuration elements. ``Use $event->getParametersFromConfig('HelloWorldBundle')`` to retrieve them from the plugin’s configuration file.
823
+
.. vale off
824
+
825
+
Modify configuration before saving
826
+
----------------------------------
827
+
828
+
To modify the form data before saving, use the ``ConfigEvents::CONFIG_PRE_SAVE event``. This event is triggered just before values are saved to the ``local.php`` file, allowing the Plugin to adjust them.
829
+
830
+
Register the event subscriber
831
+
-----------------------------
832
+
833
+
Register the subscriber through the Plugin’s configuration in the ``services[events]`` in :ref:`plugins/config:Service config items`. This ensures that the plugin listens for the events and reacts accordingly.
834
+
835
+
836
+
Config form
837
+
===========
838
+
839
+
The form type is used to generate the form fields in the main configuration form. See the :doc:`Forms documentation</components/forms>` for more information about using form types.
840
+
841
+
Remember that the form type must be registered through the Plugin’s config in the ``services[forms]`` in :ref:`plugins/config:Service config items`
842
+
.
843
+
844
+
Below is an example of a form type class that adds a custom configuration option to the Plugin's configuration form.
Registering a form theme as ``HelloWorldBundle:FormTheme\Config`` in the event listener tells the ConfigBundle to look in the HelloWorldBundle’s ``Resources/views/FormTheme/Config`` folder for templates. Specifically, it will look for a template named ``_config_{formAlias}_widget.html.twig``, where ``{formAlias}`` is the same as the ``formAlias`` set in the Plugin’s ``ConfigEvents::CONFIG_ON_GENERATE`` event listener.
881
+
882
+
The template should be structured in a panel format to match the rest of the configuration UI.
883
+
884
+
Below is an example of how the template should be structured:
0 commit comments