-
Notifications
You must be signed in to change notification settings - Fork 0
Using Joomla! plugins to handle FOF events
All FOF events issued by the Controller, Model, View and Dispatcher classes are handled both internally, with specific object methods, any by automatically triggering Joomla! plugin events. The plugin events can be handled by standard Joomla! system plugins. Below we will see what is the naming convention for these automatically triggered Joomla! plugin events by each class.
Every onFooBar
dispatcher event triggers the Joomla! plugin event onComSomethingDispatcherFooBar
.
For example, the dispatcher event onBeforeDispatch of the component com_example triggers the Joomla! plugin event onComExampleDispatcherBeforeDispatch
.
Every onFooBar
controller event triggers the Joomla! plugin event onComSomethingControllerViewnameFooBar
.
For example, the controller event onBeforeRead
of the component com_example
and view item
triggers the Joomla! plugin event onComExampleControllerItemBeforeRead
.
Every onFooBar
model event triggers the Joomla! plugin event onComSomethingModelModelnameFooBar
.
For example, the model event onBeforeSave
of the component com_example
and model items
triggers the Joomla! plugin event onComExampleModelItemsBeforeSave
.
Every onFooBar
view event triggers the Joomla! plugin event onComSomethingViewViewnameFooBar
.
For example, the view event onBeforeRead
of the component com_example
and view item
triggers the Joomla! plugin event onComExampleViewItemBeforeRead
.
The first parameter passed to the plugin event handlers is the Model, View, Controller or Dispatcher object triggering the event. It is followed by all the other parameters passed to the event handler.
For example, let's consider the onBeforeSave
event of the DataModel. When you create a method handler in your DataModel object the method signature is:
protected method onBeforeSave(&$data);
When creating a plugin event handler the method signature is:
protected method onComExampleModelItemBeforeSave(Acme\Example\Model\Item $model, &$data);
The $model
parameter holds a reference to the model object instance which triggered the event you're handling in this plugin event handler.
Currently the only way to do that is by overriding the triggerEvent
method of the Dispatcher, Controller, Model and View classes. However, we don't recommend it for two reasons:
- Future features of FOF may depend on the triggerEvent implementation. If you don't keep up it's likely that future FOF versions won't play nicely with your component. Remember that changes to the protected triggerEvent methods are NOT considered b/c breaks and can occur at any minor or point release of FOF.
- The reason we provide the automatic Joomla! plugin calls is to let site integrators from customising your extension's behaviour without making core hacks. Core hacks make it impossible to update extensions, resulting in their clients ending up with obsolete versions of your component with all the bugs you've fixed in the meantime. These people will perceive your software as a buggy, unmaintained pile of crap and lose you business.
Therefore we consider that it's in your best interest to NOT disable this feature.
FOF (Framework on Framework) and its documentation are Copyright © 2010-2020 Nicholas K. Dionysopoulos / Akeeba Ltd.
FOF is Open Source Software, distributed under the GNU General Public License, version 2 of the license, or (at your option) any later version.
The FOF Wiki content is provided under the GNU Free Documentation License, version 1.3 of the license, or (at your option) any later version.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found on the GNU site.