Hello developers,
long time ago there was a proposal in MDL-44078 to add support for hooks as a replacement for lib.php plugin callbacks. Hooks main purpose would be to allow two-way communication between 2 or more plugins.
I would like to propose it again because I believe that hooks using autoloaded classes would be much easier to use than poorly documented lib.php plugins callbacks.
For more details see MDL-74954, in short the hook classes would be stored in some_plugin\hook\ namespace extending \core\hook\base class. Other plugins could register hook callbacks by adding file db/hooks.php. Overall it would be very similar to events.
<?php // Contents of file admin/tool/recyclebin/db/hooks.php $callbacks = [ [ 'hook' => core\hook\course_delete_pre::class, 'callback' => 'tool_recyclebin\hook_callbacks::course_delete_pre', 'priority' => 0, // Execute as the last one to get more consistency. ], ];
All hook meta data would be included in the hook class, so we could even create a simple administrative page that lists all available hooks, their callbacks and even deprecated lib.php functions.