Interface to allow plugins interact with core (hooks)

Interface to allow plugins interact with core (hooks)

Marina Glancy -
回帖数:5
Core developers的头像 Moodle HQ的头像 Moodle Workplace team的头像 Peer reviewers的头像 Plugin developers的头像 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

回复Marina Glancy

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

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 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.

回复Tim Hunt

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

Petr Skoda -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 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.
回复Petr Skoda

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

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 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.

回复Petr Skoda

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

Bob Puffer -

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