-
Addons in the Backend
If you create an addon with an addon.json file you have a bit of Vanilla that can be toggled on and off. Addons bring a lot to the table in the backend beyond this little bit of user interface though. Creating PHP Classes in an Addon Configuring the Container in an Addon
-
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; }…
-
Creating PHP Classes in an Addon
Addons use a special, optimized autoloader besides composer. As a result addons can be a little more flexible with their names, but it is still recommended to treat them as if they are PSR-4 style. You may find some addons not respecting this convention. If you'd like to rename some be sure to follow through with a…
-
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…
-
Configuring the Container in an Addon
Vanilla makes heavy use of a dependency injection container. This document outlines how to configure it through an addon. Creating a ContainerRules Class This is the preferred way to configure an addon since the 2021.024 release. Create a new class in the Addon namespace of your addon. For example the dashboard container…
-
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…
-
Registering Event Handlers in an Addon
There are a few different ways to fire or dispatch events. This document will show where and how to create handlers for them. Using the EventHandlers interfaces An addon can have many event handler interfaces, and it is preferred to have multiple small sets of event handlers rather than 1 large set. This is because to…
-
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) {…