There is one more thing we need to do first. We need to know how to attach listeners to the event dispatcher.
When we create a new plugin, if we are using functions, we must inform the application of each function and event. We do this using the application’s registerEvent()
method. The method accepts two parameters, the name of the event and the name of the handler. This acts as a pass-through method for the global event dispatcher register()
method.
Technically the name of the handler can be the name of a class. We rarely need to use the method in that context because when we load a plugin that defines a class, Joomla! automatically registers the class and events.
For example, the core Joomla! search component uses plugins to search for results. The plugin that searches content articles uses the function plgSearchContent()
to handle the onSearch
event. This is how the function is registered:
$mainframe->registerEvent('onSearch', 'plgSearchContent');