-
Legacy Event Examples
Inject the the current user’s roles into every page Sometimes you may want to adjust parts of the template based on the roles the current user. This will gather the roles of the current user and inject them into the smarty template. public function base_render_before($sender) { if (inSection('Dashboard')) { return; }…
-
Using Events with the EventManager
Events are a fundamental way for different addons to communicate with each other. Events are fired with and any addon can hook into / listen to these events and respond to them. The EventManager is responsible for creating and responding to events in Vanilla. Getting the Event Manager The proper way to get the event…
-
Using Legacy Events with Gdn_Pluggable
Gdn_Pluggable The EventManager class represents the modern way of firing and handling events in Vanilla. Previously events were fired through the PluginManager or through and abstraction Gdn_Pluggable. Lots of Vanilla classes extend from Gdn_Pluggable. Almost every class beginning with Gdn extends…
-
Using PSR-14 Events with the EventManager
PHP defines PSR-14 for event dispatching. This is implemented using Vanilla's \Garden\EventManager::dispatch() and Vanilla's \Garden\PsrEventHandlersInterface. Dispatching an Event First get an instance of the EventManager by dependency injecting it. public function __construct(\Garden\EventManager $eventManager) {…