How to develop a Mautic plugin: Getting Started
When I launched my first application, I wanted an open source tool for mailing (I am huge fan of open source tool). After some research I found Mautic an open source platform for marketing automation.
I immediately fell in love with it because it have fundamental functionalities I needed and the developers are working very hard everyday to improve it. But after a while, I started to want more so I decided to develop my own plugin since Mautic have a framework to do that. In this article and the next ones, I will share experiences I got during my journey of developing my Mautic plugin.
We will start with how to configure a HelloWord plugin in this article and we will move to more specific subjects like Permission Management, MVC, … in the next. But before start a plugin it is necessary to configure the development environment.
Setup the Dev environment
Installation for development
In production mode, you just have to download it on your server and follow some few steps to install. But when you want to develop a Mautic plugin you need to install it in development mode. To do that, first you must have composer and git install on your server. Just clone the source from GitHub repository and open your browser to complete the installation.
Since you want to have deploy you plugin on the production, on I strongly advise you to use this method to install the production. For example to develop my plugin I needed to integrate a telegram library: the using this method in production allowed me in integrate the library in production also.
Configure your DEV environment
Mautic (based on Symfony) have three environments: prod, test and dev. Test is for unit testing, prod is for production and dev is what interest us: for the development.
The prod environment is the default environment accessible through index.php.
For the plugin development we will use the DEV one, accessible through index_dev.php
In production, Mautic already provide a script you can run the upgrade. But in development mode, you need to use git and some other commands to make the upgrade. Each time a new version is release, you can follow those steps to upgrade your Mautic:
- Move in the your Mautic folder un make a git pull: git pull
- Switch to the branch: git checkout -b [tag-name] (a new branch is generated for each new release. You can check the github repository to find the name of the branch: https://github.com/mautic/mautic)
- Change composer.json to add custom library if necessary then update composer: composer update
- Migrate the doctrine schema: php app/console doctrine:migrations:migrate (php app/console doctrine:schema:update –dump-sql can be use to see changes)
Initialize your Mautic plugin: HelloWord
Now that you environment is ready, you can start with your plugin. To start a plugin you just have to create in a folder in plugins at the root of your mautic folder. The folder name must have this format: Mautic[bundlename]Bundle (expl: MauticHelloWordBundle).
Now you need to create at least the structure below to be able to have a mautic plugin:
Below the minimum code for MauticHelloWorldBundle.php
class HelloWorldBundle extends PluginBundleBase
// Nothing more required
And to have more information about config file Kindly follow this link
Thank you for reading this article. This is article is just a the first of a series. Since I am currently work with Mautic I will try to share my experience.