Skip to content

Using Joomla! plugins to handle FOF events

Nicholas K. Dionysopoulos edited this page Feb 5, 2015 · 2 revisions

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.

Dispatcher

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.

Controller

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.

Model

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.

View

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.

Differences between plugin and method event handlers

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.

How do I disable this feature?

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.

Clone this wiki locally