phpBB

Development Wiki

Difference between revisions of "Add Events"

From phpBB Development Wiki

(Moved to new docs)
 
(24 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>
+
$vars = array('arrayvariable');
+
$event = new phpbb_event_data(compact($vars));
+
$phpbb_dispatcher->dispatch('identifer', $event);
+
extract($event->get_data_filtered($vars));
+
</php>
+
Let's dissect that code<br />
+
 
+
== Dissection ==
+
<pre class="narrow-codebox"> <nowiki>global $phpbb_dispatcher</nowiki></pre>
+
When its in a function this will need adding beforehand:
+
<br /><br />
+
 
+
<pre class="codebox"> <nowiki>$vars = array('arrayvariable');</nowiki></pre>
+
This just defines the variable vars as the variable for the array.
+
<br /><br />
+
 
+
<pre class="codebox"> <nowiki>$event = new phpbb_event_data(compact($vars));</nowiki></pre>
+
This won't need any changes and is beyond the scope of this article.
+
<br /><br />
+
 
+
<pre class="codebox"> <nowiki>$phpbb_dispatcher->dispatch('identifier', $event);</nowiki></pre>
+
This just sets the identifier name (see below) and input parameter which is event as per the previous line.
+
The identifer is the name for the hook. If its in the core it should be prefixed by `core.` but if its in an extension you should prefix it with a unique string related to your extension to prevent clashes with other extensions.
+
<br /><br />
+
 
+
<pre class="codebox"> <nowiki>extract($event->get_data_filtered($vars));</nowiki></pre>
+
This gets the data from the hook. This won't need changing.
+
<br /><br />
+
 
+
==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.