Plugin Developer Overview

From Joomla! Documentation

This article is tagged because itNEEDS TECHNICAL REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.More pages that need help similar to this one are here.NOTE-If you feel the need is satistified, please remove this notice.Reason: This is way more out of date than I thought :( - going to need serious work

This article is for Joomla! CMS Version(s)

Joomla! 1.5 introduced the JPlugin class. In the effort to move Joomla! toward a more efficient object-oriented framework, a new plugin system has been developed which follows the Observer pattern. Plugins are observer classes that attach to a global event dispatcher object in the Joomla! core. What does this mean in English? It means that either the Joomla! core or a third party component or module can trigger an event which causes one or more plugins to execute some code.

Implementation

The implementation of the plugin system is that of an observer pattern. It has two parts, an observer class, JPlugin, and an observable class, JEventDispatcher (changed to JEventDispatcher in ).

One is the constructor which actually gets executed by the parent class of this class JObserver. The following is what happens in the constructor:

// Register the observer ($this) so we can be notified$subject->attach($this);// Set the subject to observe$this->_subject =&$subject;

This attaches the JPlugin to an observable object. In the case of plugins, they observe the JEventDispatcher object.

The second important thing to note is the update method. The update method is passed an array from its trigger. The array contains two elements - the event and the arguments. Once the update method receives this array it extracts the event and removes it from the arguments. It then calls a method of name ‘event’ (passing the arguments array) and returns its response.