Interface to allow plugins interact with core (hooks)

Interface to allow plugins interact with core (hooks)

by Marina Glancy -
Number of replies: 5
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

This is a proposal for mini-API that can ask multiple plugins if they would like to return some data or change some object.

It is already implemented in Moodle using callbacks, hooks just provide better documentation and faster implementation (by caching the list of plugins responding to particular hook).

Examples: allow not only modules but also blocks and other plugin types to interact with course reset process (add fields to the form, etc), allow modules or other plugin types to return chunks of data for recent activity report/block, allow plugins to alter navigation, etc.

 

This is NOT a specification yet, we are trying to understand what development community thinks about it, will it make devs life easier or more complicated. I expect a lot of comments like "do not overcomplicate, there are already many ways to do it".  Would be nice to hear other point of view, what potential examples of hook usages can you imagine.

The main difference with callbacks is that they are always limited to one plugin type, where hooks can execute callbacks from all plugin types at once.

Issue: MDL-44078

Average of ratings: -
In reply to Marina Glancy

Re: Interface to allow plugins interact with core (hooks)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Why does this need a new concept. Why not just cache the list of plugins that implement each callback? That does not require anyone to change their code. It just requires a bit of development in Moodle core to improve performance so that we can afford to search for callbacks in more types of plugins.

In reply to Tim Hunt

Re: Interface to allow plugins interact with core (hooks)

by Petr Skoda -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers
Hello, it is no new concept, the hooks were proposed to share as much as possible with the new events, but with a lot more flexibility and fewer restrictions. The main difference is the possibility of two way general communication. Compared to the old events the hooks should be a lot better documented and easier to implement.
In reply to Petr Skoda

Re: Interface to allow plugins interact with core (hooks)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I don't understand. Old events were replaced by new events. Therefore, hooks are a new concept.

Before making a new things that you say "should be a lot better documented and easier to implement" why don't you first make sure that new events really is better documented and easy to implement for plugin-writers.

In reply to Petr Skoda

Re: Interface to allow plugins interact with core (hooks)

by Bob Puffer -

One of the best ideas I've seen hit the street for quite a while. Thanks