SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 188 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

For example, a plugin
with the name myplugin in the group foobar might define the JPlugin subclass
plgFoobarMyplugin.
This example is designed to handle two events: onPrepareFoobar and
onAfterDisplayFoobar:
// import the JPlugin class
jimport('joomla.event.plugin');
/**
* My Plugin event listener
*/
Plugin Design
[ 140 ]
class plgFoobarMyplugin extends JPlugin
{
/**
* handle onPrepareFoobar event
*
* @param object Foobar to prepare
*/
function onPrepareFoobar(&$foobar)
{
$foobar->name = JString::strtoupper($foobar->name);
}
/**
* handle onAfterDisplayFoobar event
*
* @param object Foobar which is being displayed
* @return string XHTML to display after the Foobar
*/
function onAfterDisplayFoobar(&$foobar)
{
return '

'.JText::_('Foobar Name converted to upper case by
My Plugin').'

';
}
}
The first thing that should have struck you about this example is that we have not
bothered to register any events with the global event dispatcher. The advantage
of using classes is we do not need to do this, so long as we follow the strict class
naming convention.


Pages:
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200