1Plugin bootstrap
2################
3
4In order to bootstrap your plugin as of Elgg 3.0 you can use a bootstrap class. This class must implement
5the ``\Elgg\PluginBootstrapInterface`` interface, but it's recommended you extend the ``\Elgg\PluginBootstrap`` abstract
6class as some preparations have already been done.
7
8If you only need a limited subset of the bootstrap functions your class can also extend the ``\Elgg\DefaultPluginBootstrap`` class,
9this class already has all the functions of ``\Elgg\PluginBootstrapInterface`` implemented. So you can overload only the functions you need.
10
11.. contents:: Contents
12   :local:
13   :depth: 2
14
15Registering the bootstrap class
16===============================
17
18You must register your bootstrap class in the ``elgg-plugin.php`` file.
19
20.. code-block:: php
21
22	return [
23		// Bootstrap must implement \Elgg\PluginBootstrapInterface
24		'bootstrap' => MyPluginBootstrap::class,
25	];
26
27Available functions
28===================
29
30->load()
31--------
32
33Executed during ``plugins_load``, ``system`` event
34
35Allows the plugin to require additional files, as well as configure services prior to booting the plugin.
36
37->boot()
38--------
39
40Executed during ``plugins_boot:before``, ``system`` event
41
42Allows the plugin to register handlers for ``plugins_boot``, ``system`` and ``init``, ``system`` events, as
43well as implement boot time logic.
44
45->init()
46--------
47
48Executed during ``init``, ``system`` event
49
50Allows the plugin to implement business logic and register all other handlers.
51
52->ready()
53---------
54
55Executed during ``ready``, ``system`` event
56
57Allows the plugin to implement logic after all plugins are initialized.
58
59->shutdown()
60------------
61
62Executed during ``shutdown``, ``system`` event
63
64Allows the plugin to implement logic during shutdown.
65
66->activate()
67------------
68
69Executed when plugin is activated, after ``activate``, ``plugin`` event and before ``activate.php`` is included.
70
71->deactivate()
72--------------
73
74Executed when plugin is deactivated, after ``deactivate``, ``plugin`` event and before ``deactivate.php`` is included.
75
76->upgrade()
77-----------
78
79Registered as handler for ``upgrade``, ``system`` event
80
81Allows the plugin to implement logic during system upgrade.
82
83Available helper functions
84==========================
85
86This assumes your bootstrap class extends the ``\Elgg\PluginBootstrap`` abstract class or the ``\Elgg\DefaultPluginBootstrap`` class.
87
88->elgg()
89--------
90
91Returns Elgg's public DI container. This can be helpfull if you wish to register plugin hooks or event listeners.
92
93.. code-block:: php
94
95	$hooks = $this->elgg()->hooks;
96	$hooks->registerHandler('register', 'menu:entity', 'my_custom_menu_callback');
97
98	$events = $this->elgg()->events;
99	$events->registerHandler('create', 'object', MyCustomObjectHandler::class);
100
101->plugin()
102----------
103
104Returns plugin entity this bootstrap is related to. This makes it easier to get plugin settings.
105
106.. code-block:: php
107
108	$plugin = $this->plugin();
109	$my_setting = $plugin->getSetting('my_setting');
110