2

I'm trying to create a plugin that fires when a menu item is saved, but I'm having trouble finding an event to listen to. Sor far I have

         function onContentAfterSave()
         {
                var_dump('contentAfterSave');exit;
                /*
                 * Plugin code goes here.
                 * You can access database and application objects and parameters via $this->db,
                 * $this->app and $this->params respectively
                 */
                return true;
        }
        function onSave()
        {
                var_dump('OnSave');exit;
                /*
                 * plugin code goes here.
                 * you can access database and application objects and parameters via $this->db,
                 * $this->app and $this->params respectively
                 */
                return true;
        }
        function onExtensionAfterSave()
        {
                var_dump('OnExtensionSave');exit;
                /*
                 * plugin code goes here.
                 * you can access database and application objects and parameters via $this->db,
                 * $this->app and $this->params respectively
                 */
                return true;
        }

But not of those are firing. Is there a different event I should be listening to?

3

onContentAfterSave() is the right one.

It appears in com_menus, in the menu item model's save function: (administrator\components\com_menus\models\menu.php - line 240)

// Trigger the after save event.
$dispatcher->trigger('onContentAfterSave', array($this->_context, &$table, $isNew));

I ran a hello world test by adding a die("hello world") to the onContentAfterSave in plugins\system\fields\fields.php and this is triggered on saving a menu item.

I suggest you compare your plugin to that one to see if there is anything you have missed.

(NB the system\fields plugin appears to be new to Joomla 3.7, so it may not exist if you are running an older version)

  • Thanks, I think I'm running 3.4.5, we may have to add that trigger until we can upgrade – ContextSwitch May 3 '17 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.