Mautic Community Forums

Extending campaign - adding new action via plugin

Hi,



I need to add action in the campaign module using plugin. I have refereed to the documentation but it seems that scope is very less. They have provided the initial steps only not explained deeper integration. Please help if somebody has built something like this .



https://developer.mautic.org/#extending-campaigns



Thanks in advance.

Hi,

I need to add action in the campaign module using plugin. I have refereed to the documentation but it seems that scope is very less. They have provided the initial steps only not explained deeper integration. Please help if somebody has built something like this .

https://developer.mautic.org/#extending-campaigns

Thanks in advance.

The best is to look at the existing code. Plugins can be as powerful as the core bundles. So if you look at for example how AssetBundle subscribes the “asset.download” event:

https://github.com/mautic/mautic/blob/staging/app/bundles/AssetBundle/EventListener/CampaignSubscriber.php

you can do it similarly in your plugin.

I have resolved the above myself. We have successfully added the action in the campaign and moving forward for creating the forms etc. IT being a great help from your side and will followup you in case i would any help.

I really appreciate your quick responses.

Thanks for the reply.

We read your shared example for the core bundle. But we like to know how these functions are called ‘getSubscribedEvents’,‘onCampaignBuild’ and ‘onAssetDownload’ because we already tried to create plugin by having eventlistener but nothing worked. Please review the following plugin of ours and try to help us.

socialadsdev.wpengine.com/HelloWorldBundle.zip

Thanks in advance.

Thanks for the quick response.

As per your last help we have defined the service in the config file by providing form and event but now it start giving syntax error in the campaignsubscriber file and we are not able to rectify it.

Error:
FatalErrorException in CampaignSubscriber.php line 43: Parse Error: syntax error, unexpected ‘‘formTypeOptions’’ (T_CONSTANT_ENCAPSED_STRING), expecting ')

Please help us , it would be highly appreciated.

Thanks

You are missing a comma after

'formTheme'       => 'HelloWorldBundle:FormThemeSubmitAction'

I noticed you’re using the code from dev docs. I fixed the comma there:

https://github.com/mautic/developer-documentation/pull/7

I glanced to the code quickly. I noticed the event listeners aren’t defined in the config.php. The services like subscribers and forms has to be defined there. An example:

https://github.com/mautic/mautic/blob/staging/app/bundles/AssetBundle/Config/config.php#L69

Don’t forget to clear cache every time you modify any config file.

Thanks , i also got the same and resolved but again in the next step i got the following error:

Error:
RuntimeException in DebugClassLoader.php line 187: The autoloader expected class “MauticPluginHelloWorldBundleEventListenerCampaignSubscriber” to be defined in file “/path to server/muatic/plugins/HelloWorldBundle/EventListener/CampaignSubscriber.php”. The file was found but the class was not in it, the class name or namespace probably has a typo.

socialadsdev.wpengine.com/HelloWorldBundle.zip

I really appreciate your help.

Hi Synapseindia - Does your HelloWorldBundle plugin that you link to above work for you? I’m trying to develop a plugin that will add a campaign action that triggers an post of a lead’s data to some arbitrary URL. It looks like the plugin that you were working on add campaign actions so I was hoping to use that as a reference.

Whenever I install the plugin I always end up breaking my site but once I remove the plugin things go back to normal. I suspect that I have a permission issue on my server but I’m not sure exactly. I was hoping to get info from you as to expected behavior of your plugin, for example, will it work if I install it “as is” and will it add a campaign action?

Thanks!