Config file
Mautic leverages a simple array based config file to register routes, menu items, services, Categories, and configuration parameters.
General config items
Mautic recognizes the Plugin through the general config options.
<?php
// plugins/HelloWorldBundle/Config/config.php
return [
'name' => 'Hello World',
'description' => 'This is an example config file for a simple Hello World plugin.',
'author' => 'Someone Awesome',
'version' => '1.0.0',
// ...
Key |
Type |
Description |
---|---|---|
|
string |
Human readable name for the Plugin that displays in the Plugin Manager. |
|
string |
Optional description of the Plugin. This is currently not displayed in the UI. |
|
string |
Author of the Plugin for attribution purposes. |
|
string |
The version should be in a format compatible with PHP’s standardized version strings. The Plugin Manager uses PHP’s |
Routing config items
Routes define the URL paths that execute the specified controller action. Register routes with Mautic through the routes
key in the Plugin’s config. Define each route under one of Mautic’s supported firewalls with a uniquely identifying key and the route’s definition.
<?php
// ...
'routes' => [
'main' => [
'plugin_helloworld_world' => [
'path' => '/hello/{world}',
'controller' => [MauticPlugin\HelloWorldBundle\Controller\DefaultController, 'world'],
'defaults' => [
'world' => 'earth',
],
'requirements' => [
'world' => 'earth|mars',
],
],
'plugin_helloworld_list' => [
'path' => '/hello/{page}',
'controller' => [MauticPlugin\HelloWorldBundle\Controller\DefaultController, 'index'],
],
'plugin_helloworld_admin' => [
'path' => '/hello/admin',
'controller' => [MauticPlugin\HelloWorldBundle\Controller\DefaultController, 'admin']
],
],
'public' => [
'plugin_helloworld_goodbye' => [
'path' => '/hello/goodbye',
'controller' => MauticPlugin\HelloWorldBundle\Controller\GoodbyeController::class, // assumes an invokable class
],
'plugin_helloworld_contact' => [
'path' => '/hello/contact',
'controller' => MauticPlugin\HelloWorldBundle\Controller\ContactController::class, // assumes an invokable class
],
],
'api' => [
'plugin_helloworld_api' => [
'path' => '/hello',
'controller' => MauticPlugin\HelloWorldBundle\Controller\Api\HelloController::class, // assumes an invokable class
'method' => 'GET',
],
],
],
// ...
Routing firewalls
The following firewalls are available to routes.
Key |
URL prefix |
Description |
---|---|---|
|
|
Routes that require API User authentication such as OAuth 2.0. |
|
|
Routes that require standard User authentication to access secure parts of the UI. |
|
|
Routes that are public facing and don’t require any User authentication. |
|
|
A special public firewall compiled after all other routes and namely used by Landing Pages to recognize custom Landing Page URLs. |
Each firewall accepts an array of defined routes. Each key, the route’s name, must be unique across all bundles and firewalls. Paths must be unique across the same firewall. Order does matter as Symfony uses the first matching route.
Warning
Each route’s name must be unique across all bundles and firewalls and paths must be unique within the same firewall.
Warning
Order of routes matters as Symfony uses the first route that matches the URL.
Route definitions
Route definitions define the route’s method, path, controller, parameters, and others defined below.
Key |
Is required? |
Type |
Description |
---|---|---|---|
|
yes |
string |
Defines the URL path for the route. Define placeholders for parameters using curly brackets. Symfony passes values for parameters into the controller method arguments that match by name. For example, |
|
yes |
string|array |
Defines the controller and function to call when the path matches. There are three supported formats. The legacy string format, |
|
no |
string |
Restricts the route to a specific method. For example GET, POST, PATCH, PUT, OPTIONS. Symfony recognizes all methods by default. |
|
no |
array |
Defines the default values for path placeholders as key/value pairs. For example, given the path, |
|
no |
array |
Defines regular expression patterns for placeholders as key/value pairs that the URL path must match. For example, visiting |
|
no |
string |
Sets the “request format” of the Request object such as |
|
no |
boolean |
If the firewall is |
Special routing parameters
Mautic defaults the following route definitions if not declared otherwise by the Plugin.
Parameter |
Default value |
Description |
---|---|---|
|
|
Recognizes only digits for page parameters - used in pagination. |
|
|
Routes that views or edits a specific entity may leverage this. |
|
|
Requires a digit if using the |
Advanced routing
Configure custom routes through writing a listener to the \Mautic\CoreBundle\CoreEvents::BUILD_ROUTE
event. Listeners to this event receives a Mautic\CoreBundle\Event\RouteEvent
object. Mautic dispatches an event for each firewall when compiling routes.
- Mautic\CoreBundle\Event\RouteEvent
- getType()
- Returns:
The route firewall for the given route collection.
- Return type:
string
- getCollection()
- Returns:
Returns a RouteCollection object that can be used to manually define custom routes.
- Return type:
\Symfony\Component\Routing\RouteCollection
- addRoutes(string $path)
Load custom routes through a resource file such as yaml or XML.
- Parameters:
$path (
string
) – Path to the resource file. For example,@FMElfinderBundle/Resources/config/routing.yaml
.
- Return type:
void
Debugging routes
Use the follow commands to help debug routes:
Command |
Description |
---|---|
|
Lists all registered routes. |
|
Lists the definition for the route |
|
Lists the route that matches the URL path |
Service config items
Services define the Plugin’s classes and their dependencies with Mautic and Symfony. Services defined within specific keys are auto-tagged as noted below.
<?php
// ...
'services' => [
'events' => [
'helloworld.leadbundle.subscriber' => [
'class' => \MauticPlugin\HelloWorldBundle\EventListener\LeadSubscriber::class,
],
],
'forms' => [
'helloworld.form' => [
'class' => \MauticPlugin\HelloWorldBundle\Form\Type\HelloWorldType::class,
],
],
'helpers' => [
'helloworld.helper.world' => [
'class' => MauticPlugin\HelloWorldBundle\Helper\WorldHelper::class,
'alias' => 'helloworld',
],
],
'other' => [
'helloworld.mars.validator' => [
'class' => MauticPlugin\HelloWorldBundle\Form\Validator\Constraints\MarsValidator::class,
'arguments' => [
'mautic.helper.core_parameters',
'helloworld.helper.world',
],
'tag' => 'validator.constraint_validator',
],
],
],
// ...
Service types
For convenience, Mautic auto-tags services defined within specific keys.
Key |
Tag |
Description |
---|---|---|
|
|
Registers the service with Symfony as a console command. |
|
|
Controllers are typically autowired by Symfony. However, you can register controllers as services to manage your own dependency injection rather than relying on Symfony’s service container. |
|
|
Registers the service with Symfony as an event subscriber. |
|
|
Registers the service with Symfony as a custom form field type. |
|
|
Registers the service with Symfony as a PHP template helper. The service definition must include an |
|
|
Deprecated. Use service dependency injection instead. |
|
|
Registers the service with Mautic’s permission service. |
|
n/a |
You can use any other key you want to organize services in the config array. Note that this could risk incompatibility with a future version of Mautic if using something generic that Mautic starts to use as well. |
Service definitions
Key each service with a unique name to all of Mautic, including other Plugins.
Key |
Is required? |
Type |
Description |
---|---|---|---|
|
yes |
string |
Fully qualified name for the service’s class. |
|
no |
array |
Array of services, parameters, booleans, or strings injected as arguments into this service’s construct. Wrap parameter names in |
|
conditional |
string |
Used by specific types of services. For example, services defined under |
|
no |
string |
Define an alias for this service in addition to the name defined as the service’s key. Note that Mautic sets the service’s class name as an alias by default. |
|
no |
array |
Define multiple aliases for this service in addition to the name defined as the service’s key. Note that the service’s class name is set as an alias by default. |
|
no |
string |
Define a tag used by Symfony when compiling the container. See Mautic service tags for Mautic specific tags. |
|
no |
array |
An array of tags when there are more than one. See Mautic service tags for Mautic specific tags. This supersedes |
|
no |
array |
Some tags have special arguments definable through an array of tagArguments. If using |
|
no |
array |
Define a factory to create this service. For example, |
|
no |
array[] |
Define methods to call after the service is instantiated. Use an array of arrays with keys as the method name and values the arguments to pass into the given method. For example, |
|
no |
string |
Name of another service to override and decorate. The original service becomes available as |
|
no |
boolean |
Defines the service as public and accessible through the service container. By default, all Mautic services are public. Set this to |
|
no |
boolean |
Configure the service as synthetic meaning it gets set during run time. See Symfony 4 synthetic services. |
|
no |
string |
Include the specified file prior to loading the service. Symfony uses PHP’s |
|
no |
array|string |
Callable to use as a configurator to configure the service after its instantiation. See Symfony 4 service configurators. |
|
no |
boolean |
Configure this service as an abstract/parent service. Symfony ignores this until Mautic addresses https://forum.mautic.org/t/support-symfony-abstract-parent-services/21922. |
|
no |
boolean |
Define the service with lazy loading. Symfony ignores this until Mautic addresses https://forum.mautic.org/t/supporty-symfony-lazy-services/21923. |
Category config items
Use categories
to define Category types available to the Category manager. See Categories.
<?php
// ...
'categories' => [
'plugin:helloWorld' => 'mautic.helloworld.world.categories',
],
// ...
Parameters config items
Configure parameters that are consumable through Mautic’s CoreParameterHelper
, passed into services with %mautic.key%
, or read from the environment via MAUTIC_KEY
. See Configuration parameters for more information.
<?php
// ...
'parameters' => [
'helloworld_api_enabled' => false,
'helloworld_supported_worlds' => ['earth', 'mars', 'jupiter',],
],
// ...
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
.
Note
Parameters aren’t exposed to the UI by default. See Configuration for more information.