phpBB

Development Wiki

Difference between revisions of "Add Events"

From phpBB Development Wiki

(How to add a ledge to templates)
(How to add a ledge to templates)
Line 25: Line 25:
 
This is very simple to do
 
This is very simple to do
 
<pre><!-- RUNHOOKS identifier --></pre>
 
<pre><!-- RUNHOOKS identifier --></pre>
Just replace the identifier with the name of the hook by just using underscores and lowercase letters.
+
Just replace the identifier with the name of the hook by just using underscores, numbers and lowercase letters.
  
 
==Core Ledges List==
 
==Core Ledges List==

Revision as of 10:47, 13 March 2012

What are ledges?

A ledge is a hook location. When an extension wishes to hook its functionality into the phpBB core at a certain point, it can do so only at available hook locations, or ledges. For more information, see the wiki article for hooks.

How to add a ledge to everything except templates

You would add a ledge you would use this code:

global $phpbb_dispatcher

$vars 
= array('var1''var2');
$event = new phpbb_event_data(compact($vars));
$phpbb_dispatcher->dispatch('identifer'$event);
extract($event->get_data_filtered($vars));

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

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

Identifier will need to be changed to the name of the ledge. This should be prefixed by `core.` if it is a ledge in the core and not in your extension (you can have ledges 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 hooks. 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 a ledge and just need to document it as below.

How to add a ledge to templates

This is very simple to do

<!-- RUNHOOKS identifier -->

Just replace the identifier with the name of the hook by just using underscores, numbers and lowercase letters.

Core Ledges List

If you add a ledge to the core you need to ensure you add it to the ledges list to ensure it remains a comprehensive and exhaustive list.

Requested ledges can also be added to the list and they will be added at some point to the phpBB repository.

You can view and edit the ledges list page here

Examples of ledges being added


Based on the blog article Explaining Hooks