phpBB

Development Wiki

Difference between revisions of "Add Events"

From phpBB Development Wiki

(Moved to new docs)
 
(23 intermediate revisions by 9 users not shown)
Line 1: Line 1:
==What are ledges?==
+
This documentation has been moved to the new phpBB Development Documentation.
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==
+
[https://area51.phpbb.com/docs/dev/31x/extensions/tutorial_advanced.html#adding-a-php-event-to-your-extension Extensions: Adding a PHP event to your extension].
You would add a ledge you would use this code:
+
<php>
+
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));
+
</php>
+
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.
+
 
+
==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 [[Ledges_List|here]]
+
 
+
==Examples of ledges being added==
+
* [https://github.com/p/phpbb3/commit/15e4bdd67f69844b8f7c2387196fa3c54b66ff7c core.memberlist_profile_data ledge.]
+
* [https://github.com/p/phpbb3/commit/7e3cc2a333b4969f69622620cfd7b08ae595a219 Display forum ledges]
+
 
+
 
+
Based on the blog article [http://blog.phpbb.com/2010/10/09/explaining-hooks/ Explaining Hooks]
+
[[Category:Ledges and Hooks]]
+

Latest revision as of 18:41, 5 December 2016

This documentation has been moved to the new phpBB Development Documentation.

Extensions: Adding a PHP event to your extension.