Development Wiki

Add Events

From phpBB Development Wiki

Revision as of 00:54, 18 October 2013 by Naderman (Talk | contribs)

What are events?

When an extension wishes to hook its functionality into the phpBB core at a certain point, it can do so only where respective events are triggered. For more information, see the wiki article for listeners. Events are also known as hook location and previously ledges.

Triggering an event in PHP code

Adapt the following snippet of code to trigger an event in any PHP code.

global $phpbb_dispatcher;

$vars = array('var1''var2');

This code takes variables used by phpbb, packages them into an event object and dispatches the event to any registered listeners. Then it extracts the variables back, therefore allowing hooks to modify them. It is the magic incantation for adding events.

If an event does not need any arguments, you can use this short version:

global $phpbb_dispatcher;


You only need to register the global if you are inside a function.

Identifier will need to be changed to the name of the event. This should be prefixed by `core.` if it is an event in the core and not in your extension (you can have events in your extensions for other extensions to use). It should be unique and only use underscores and full stops/periods (for the prefix) and lowercase letters.

var1 and var2 should be replaced with the list of variables that are to be passed to listeners. Each of these variables should exist in the local scope where the ledge is being added. You can have as many as you wish inside this array or just 1.

And now you've made an event and just need to document it as below.

Triggering an event in a template

Add the following code to a template:

<!-- EVENT identifier -->

Replace the identifier with the name of the listener. Make sure to only use underscores, numbers and lowercase letters.

That's it! You've created an event and should document it as described below.

Core events List

If you add an event to phpBB rather than one of your own templates, it must be added to the events list.

You can view and edit the events list here

Examples of events being added