Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Some plugins may need to be invoked to perform certain tasks immediately before or after an action has occurred. For this reason plugins may register plugin events. These Events automatically initialize the plugin and invoke the desired event handler (i.e. callback method) when triggered. All event handlers accept a single \Blesta\Core\Util\Events\Common\EventInterface (previously an EventObject). parameter.

For performing tasks at regular intervals see Plugin Cron Tasks.

Warning
titleThe EventObject is deprecated

Blesta v4.3.0 has deprecated and replaced the EventObject $event that is passed to your event callback. Plugins will still be passed an EventObject for backward compatibility, but this will be replaced by a \Blesta\Core\Util\Events\Common\EventInterface in the future, which supports the same methods and data. This means that your plugin implementation should not check for an EventObject type unless you also support a type check on \Blesta\Core\Util\Events\Common\EventInterface.

...

Code Block
languagephp
title/plugins/my_plugin/my_plugin_plugin.php
<?php
class MyPluginPlugin extends Plugin 
{
	...

	public function getEvents()
	{
		return array([
			array([
				'event' => "Appcontroller.preAction",
				'callback' => array("this", "run")
			)]
			// Add multipleadditional events here
		)];
	}

	public function run($event) 
	{
		// This will execute when the "Appcontroller.preAction" event is triggered
	}
}

...