1

plugin code

defined( '_JEXEC' ) or die;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Event\Event;
use Joomla\Event\SubscriberInterface;

class PlgMygroupMyplugin extends CMSPlugin //implements SubscriberInterface
{
    
protected $autoloadLanguage = true;

protected $app;

//public static function getSubscribedEvents(): array
//{
//  return [
//      'getMyevent' => 'getMyevent',
//  ];
//}

/*
*
*/
public static function getMyevent()
{
    return 'OK!';
}
}

I try to call in different ways all unsuccessfully

protected function getOptions()
    {
    
    PluginHelper::importPlugin('mygroup');
    
    $results = Factory::getApplication()->triggerEvent('getMyevent');
    
    
    //$dispatcher = JDispatcher::getInstance();
    //$results = $dispatcher->trigger( 'getMyevent' );
    
    
    //$dispatcher = Joomla\CMS\Factory::getApplication()->getDispatcher();
    //$event      = new Joomla\Event\Event('getMyevent');
    //$results    = $dispatcher->dispatch('getMyevent', $event);
    
    
    //$dispatcher = Factory::getApplication()->getDispatcher();
    //$event = AbstractEvent::create('getMyevent', array());
    //$results = $dispatcher->dispatch('getMyevent', $event);

print_r($results);
}

1 Answer 1

2

The problem is that most likely all events should start with "on" when a different prefix is specified, as in my case the "get" event simply does not fire. I changed the prefix to "on" and it worked.

use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Factory;

PluginHelper::importPlugin('mygroup');
$results = Factory::getApplication()->triggerEvent('onMyevent');

The solution is found on this page issues.joomla.org

1

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.