In order to bootstrap your plugin as of Elgg 3.0 you can use a bootstrap class. This class must implement
\Elgg\PluginBootstrapInterface interface, but it’s recommended you extend the
class as some preparations have already been done.
If you only need a limited subset of the bootstrap functions your class can also extend the
this class already has all the functions of
\Elgg\PluginBootstrapInterface implemented. So you can overload only the functions you need.
Registering the bootstrap class¶
You must register your bootstrap class in the
return [ // Bootstrap must implement \Elgg\PluginBootstrapInterface 'bootstrap' => MyPluginBootstrap::class, ];
Allows the plugin to require additional files, as well as configure services prior to booting the plugin.
Allows the plugin to register handlers for
system events, as
well as implement boot time logic.
Allows the plugin to implement business logic and register all other handlers.
Allows the plugin to implement logic after all plugins are initialized.
Allows the plugin to implement logic during shutdown.
Executed when plugin is activated, after
Executed when plugin is deactivated, after
Registered as handler for
Allows the plugin to implement logic during system upgrade.
Available helper functions¶
This assumes your bootstrap class extends the
\Elgg\PluginBootstrap abstract class or the
Returns Elgg’s public DI container. This can be helpfull if you wish to register plugin hooks or event listeners.
$hooks = $this->elgg()->hooks; $hooks->registerHandler('register', 'menu:entity', 'my_custom_menu_callback'); $events = $this->elgg()->events; $events->registerHandler('create', 'object', MyCustomObjectHandler::class);
Returns plugin entity this bootstrap is related to. This makes it easier to get plugin settings.
$plugin = $this->plugin(); $my_setting = $plugin->getSetting('my_setting');