Mautic Community Forums

Plugin development

I am new in mautic, creating a plugin in mautic. I am writing code for plugin.

I have created a config.php file and write a following code for displaying a menu in admin left sidebar as per mautic tutorial.

‘menu’ => array(

‘main’ => array(

‘priority’ => 4,

‘items’ => array(

‘plugin.promocodes.index’ => array(

‘id’ => ‘plugin_promocodes_index’,

‘iconClass’ => ‘fa-globe’,

‘access’ => ‘plugin:promocodes:promo:view’,

‘children’ => array(

‘plugin.promocodes.manage_promo’ => array(

‘route’ => ‘plugin_promocodes_list’

),

‘mautic.category.menu.index’ => array(

‘bundle’ => ‘plugin:promocodes’

)

)

)

)

),

‘admin’ => array(

‘plugin.promocodes.admin’ => array(

‘route’ => ‘plugin_promocodes_admin’,

‘iconClass’ => ‘fa-gears’,

‘access’ => ‘admin’,

‘checks’ => array(

‘parameters’ => array(

‘promocodes_api_enabled’ => true

)

)

)

)

),

but I got error in my log file



will you please help me where I was wrong? What I have to do next step?



[2016-04-07 16:31:48] mautic.CRITICAL: Uncaught PHP Exception InvalidArgumentException: “Permission class not found for PromocodesBundle!” at /home/rahuldhiman/public_html/niks/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php line 151 {“exception”:"[object] (InvalidArgumentException(code: 0): Permission class not found for PromocodesBundle! at /home/rahuldhiman/public_html/niks/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php:151)"} []



Here is a log error that I have got in log file.

and mautic has stopped the working.

I am new in mautic, creating a plugin in mautic. I am writing code for plugin.
I have created a config.php file and write a following code for displaying a menu in admin left sidebar as per mautic tutorial.
‘menu’ => array(
‘main’ => array(
‘priority’ => 4,
‘items’ => array(
‘plugin.promocodes.index’ => array(
‘id’ => ‘plugin_promocodes_index’,
‘iconClass’ => ‘fa-globe’,
‘access’ => ‘plugin:promocodes:promo:view’,
‘children’ => array(
‘plugin.promocodes.manage_promo’ => array(
‘route’ => ‘plugin_promocodes_list’
),
‘mautic.category.menu.index’ => array(
‘bundle’ => ‘plugin:promocodes’
)
)
)
)
),
‘admin’ => array(
‘plugin.promocodes.admin’ => array(
‘route’ => ‘plugin_promocodes_admin’,
‘iconClass’ => ‘fa-gears’,
‘access’ => ‘admin’,
‘checks’ => array(
‘parameters’ => array(
‘promocodes_api_enabled’ => true
)
)
)
)
),
but I got error in my log file

will you please help me where I was wrong? What I have to do next step?

[2016-04-07 16:31:48] mautic.CRITICAL: Uncaught PHP Exception InvalidArgumentException: “Permission class not found for PromocodesBundle!” at /home/rahuldhiman/public_html/niks/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php line 151 {“exception”:"[object] (InvalidArgumentException(code: 0): Permission class not found for PromocodesBundle! at /home/rahuldhiman/public_html/niks/app/bundles/CoreBundle/Security/Permissions/CorePermissions.php:151)"} []

Here is a log error that I have got in log file.
and mautic has stopped the working.

Have you written a PromocodesBundle.php file which contains a PromocodesBundles that extends from PluginBundleBase as described here https://developer.mautic.org/#plugin-directory-structure?

Also which version of Mautic are you using?

v1.3.0

Yes I have written MauticPromoCodeBundle.php file.

here is my code

<?php /** * @package Mautic * @copyright 2014 Mautic Contributors. All rights reserved. * @author Mautic * @link http://mautic.org * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */ namespace MauticPluginMauticPromoCodeBundle; use MauticPluginBundleBundlePluginBundleBase; /** * Class MauticPromoCodeBundle * * @package MauticLeadBundle */ class MauticPromoCodeBundle extends PluginBundleBase { }

Hi,

I think there’s a mismatch in naming somewhere - the error says Permission class not found for PromocodesBundle so it’s looking for a PromocodesBundle.php file with PromocodesBundle class but your class name is different.

If you have changed the classname recently then it may be worth clearing the cache. Also, it’s worth noting that the class names are case sensitive as well

Linh

Looks like you have a custom Permission class called PromocodesBundle. Since your bundle is called MauticPromoCodeBundle, try nameing the permission class MauticPromoCodePermissions with the corresponding file name.

Where should I create this file.

I have created PromoCodePermissions.php this file in
MauticPromoCodeBundle/Security/Permissions/ folder

here is a code for this file .

<?php namespace MauticPluginPromocodeBundleSecurityPermissions; use SymfonyComponentFormFormBuilderInterface; use MauticCoreBundleSecurityPermissionsAbstractPermissions; /** * Class PromoCodePermissions */ class MauticPromoCodePermission extends AbstractPermissions { /** * Define available permissions * * @param $params */ public function __construct($params) { parent::__construct($params); $this->permissions = array( // Custom level 'Promo' => array( // Custom permissions 'use_telescope' => 1, 'send_probe' => 2, 'visit' => 4, // Full will almost always be included and should be significantly higher than the // others in case new permissions need to be added later 'full' => 1024 ) ); // Add standard category permissions $this->addStandardPermissions('categories'); } /** * Append the permission form fields to the Role form * * @param FormBuilderInterface $builder * @param array $options * @param array $data */ public function buildForm(FormBuilderInterface &$builder, array $options, array $data) { // Add standard category form fields $this->addStandardFormFields('promoCode', 'categories', $builder, $data); } designbyhumans.com /** * Permission set identifier; should be bundleName * * @return string */ public function getName() { return 'promoCode'; } } ?>

have a look at this https://developer.mautic.org/#creating-custom-permissions

It says getName should return exactly the bundle name which must also be the name of the file. Your bundle name is MauticPromoCode and so should be in a class called MauticPromoCodePermissions. Also I think Permissions has the s at the end which you are missing.

I am having trouble to set admin left menu in mautic through plugin.
I am not getting solution for this.