# Extending campaign - adding new action via plugin

**URL:** <https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242>\
**Category:** Development\
**Created:** [January 14, 2016, 6:55am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242 "2016-01-14T06:55:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Synapseindia](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Synapseindia](https://forum.mautic.org/u/Synapseindia)\
**Post date:** [January 14, 2016, 6:55am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/1 "2016-01-14T06:55:33Z")

</div>

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](https://developer.mautic.org/#extending-campaigns)  
  
  
  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Synapseindia](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Synapseindia](https://forum.mautic.org/u/Synapseindia)\
**Post date:** [January 14, 2016, 6:55am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/2 "2016-01-14T06:55:33Z")

</div>

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](https://developer.mautic.org/#extending-campaigns)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 14, 2016, 8:38am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/3 "2016-01-14T08:38:41Z")

</div>

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](https://github.com/mautic/mautic/blob/staging/app/bundles/AssetBundle/EventListener/CampaignSubscriber.php)

you can do it similarly in your plugin.

---

<div class="post-metadata">

**Author:** ![Synapseindia](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Synapseindia](https://forum.mautic.org/u/Synapseindia)\
**Post date:** [January 16, 2016, 6:47am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/4 "2016-01-16T06:47:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Synapseindia](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Synapseindia](https://forum.mautic.org/u/Synapseindia)\
**Post date:** [January 15, 2016, 5:37am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/5 "2016-01-15T05:37:36Z")

</div>

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](http://socialadsdev.wpengine.com/HelloWorldBundle.zip)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Synapseindia](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Synapseindia](https://forum.mautic.org/u/Synapseindia)\
**Post date:** [January 15, 2016, 11:51am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/6 "2016-01-15T11:51:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 15, 2016, 11:53am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/7 "2016-01-15T11:53:41Z")

</div>

You are missing a comma after

```auto
'formTheme' => 'HelloWorldBundle:FormThemeSubmitAction'
```

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 15, 2016, 11:58am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/8 "2016-01-15T11:58:49Z")

</div>

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

[https://github.com/mautic/developer-documentation/pull/7](https://github.com/mautic/developer-documentation/pull/7)

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [January 15, 2016, 8:32am UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/9 "2016-01-15T08:32:11Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Synapseindia](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Synapseindia](https://forum.mautic.org/u/Synapseindia)\
**Post date:** [January 15, 2016, 12:45pm UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/10 "2016-01-15T12:45:05Z")

</div>

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](http://socialadsdev.wpengine.com/HelloWorldBundle.zip)

I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![ae5000](https://avatars.discourse-cdn.com/v4/letter/a/4bbf92/32.png) [@ae5000](https://forum.mautic.org/u/ae5000)\
**Post date:** [May 11, 2017, 2:33pm UTC](https://forum.mautic.org/t/extending-campaign-adding-new-action-via-plugin/3242/11 "2017-05-11T14:33:49Z")

</div>

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!
