2

As I understand, to use Joomla! plugin events from my user code, I first need to load the plugin class (which registers the named functions as events in the event dispatcher):

JPluginHelper::importPlugin('captcha');

Then I can trigger events from my user code:

$dispatcher = JDispatcher::getInstance();
trigger('onInit');

How does the plugin system handle name collisions between events? For example, the captcha plugins have an onDisplay function/event, as do the editor plugins. What happens when I call the following after the previous code?

JPluginHelper::importPlugin('editor');
trigger('onDisplay');

I believe this will trigger the onDisplay event on both the group of captcha plugins, and the group of editor plugins. It seems like the trigger method of JEventDispatcher would need a parameter for at least the group of plugins to act on. Do I get all plugins with an onDisplay function firing, and I have to sort out what is garbage? What if a non-relevant plugin running with garbage input has an exception on that input?

1 Answer 1

2

If you want to understand more how Joomla! plugins work I recommend you to read this awesome book from an advanced Joomla! developer Jisse Reitsma.

In Joomla! All plugins are triggered by groups in a given order based by their ordering in the plugin administration page of the Joomla! backend. If a plugin within a group "A" sends some "garbage input" as you say, before another plugin with the same group "A" and the same event "E", the first plugin will get precedence if there is an error but if there is no error the last plugin of the same group "A" can still modify the input if this input is sent by reference. (using and ampersand & before it).

There is another special plugin group called "system" used for system plugins. System plugin can intercept and manipulate any event within Joomla! but they have the same laws of precedence. The last system plugin will have the opportunity to modify the input data if the previous system plugins don't have any errors.

Beware of system plugin errors, due to the nature of a system plugin, (loaded very soon in Joomla! boot process), if there is a fatal error it can break your Joomla! site.

Hope it helps you go from here.

Programming Joomla Plugins

Morever you can find the code related to the book https://github.com/jissereitsma/JoomlaPluginsBook

7
  • Please avoid posting link only answers. When your entire answer is composed of hyperlinks, it is vulnerable to becoming a dead end if the links change or get removed. Please edit your answer to include the relevant advice directly on this page, or transfer your recommended resources as a comment under the question. Commented Jan 16, 2019 at 2:15
  • Here is some resources to get you up and running. [Programming Joomla Plugins][1] Morever you can find the code related to the book github.com/jissereitsma/JoomlaPluginsBook [1]: amazon.com/Programming-Joomla-Plugins-Wanted-About/dp/… Commented Jan 16, 2019 at 11:32
  • Links are okay to have in answers, they just shouldn't be 100% links. You have reduced the value of your answer. Please add to your answer not take away. Commented Jan 16, 2019 at 11:34
  • @application2000 - now this looks like a nice, useful answer now. Voted up. :) However I would add that the namespace does not really relevant in how the plugins work. I mean from the approach of the original poster. Since the subject/observer system has relevancy and it is quite useful structure in Joomla regarding how the plugins work.
    – Zollie
    Commented Jan 16, 2019 at 12:06
  • @application2000 - in any way, your answer will be helpful for later researchers and that’s a good point. Welcome on board! :)
    – Zollie
    Commented Jan 16, 2019 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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