Welcome to the lesson II of the series Develop a Mautic plugin. If you have not read the previous article I highly recommended you to do it (you can find it here).
Mautic is based on Symfony which is a MVC PHP framework. So, develop a module in Mautic means that you will work follow the MVC paradigm but with Mautic rules. So in the article we will give a brief description of MVC then the first big step for module development: configuration of routes and menus.
MVC stand for Model View Controller which is a software architecture pattern. MVC define three components:
- Model: responsible for the interaction with your data.
- View: responsible for the presentation to the user.
- Controller: responsible for bind data from the model and display the view.
And to give access to the user you need to define routes.
In the next, we will configure routes (MVC paradigm) and menus (Mautic specification) to display routes to the user. And before we continue, we need to define one of the most important things: the key name of the module, which will be used in all our configurations.
Configurations
All configurations are done Config/config.php: routes, menus, service, categories, ... We will only focus on the configurations for basic MVC module and to do that, we only need to add route and menu configurations. As define the previous article, our module name is HelloWord and the key name is helloword. Let us configure the routes for different actions and the menu to give access to our module to a user.
Routes
Mautic have three types of routes:
- main: users need to be authenticated to have access to those routes. (/s/ will be automatically appended)
- public: those routes will be accessible for everyone authenticated or not
- api: accessible only through API secure requests (/api/ will be automatically appended)
For a route you need to define some required parameters and some other optionals, depending on your needs.
- path (required): is the path used in the browser (since Mautic is base on Symfony this path definition follows the same rules as Symfony).
- controller (required): Is the action to call when this route is triggered. We will see how to define a controller in the next article.
- method (optional): is the HTTP method (GET, POST, ...) which need to be used to trigger this route.
There are other parameters that can be defined in the route, you can find a full documentation here.
Each of your routes must have a unique name, name which will be used to refer to this route in the other configurations or in your source code.
In this article, we will only focus on the main route.
Menu
Mautic have 4 types of menus:
- main: Main menu on the left.
- admin: Admin menu accessible through the cogwheel in upper right-hand side of Mautic.
- profile: Profile menu accessible through clicking the username in upper right-hand side of Mautic.
- extra: Displays to the right of the Mautic logo in the upper left hand. Only shows if there are menu items injected.
Same like routes, menu has some parameters that you can set.
- route (optional): The name of the route to link to this menu.
- parent (optional): Display this item under another parent menu item.
There are other parameters that can be defined in the menu, you can find a full documentation here.
In this article, we will only focus on the main menu.
Config file
This is what your file will look like.
php611 B
As you can see, make a configuration file is just a matter of return a php array with a specific structure. We have routes ( with main routes within) and menu (with main menu within) and for each element you define a unique name and your configuration within.
This is the end of this article. Hope this was helpful and see you in the next article.