phpBB

Development Wiki

Difference between revisions of "Add Events"

From phpBB Development Wiki

(How to add a ledge)
(Large Update)
Line 3: Line 3:
  
 
==How to add a ledge==
 
==How to add a ledge==
You would add a ledge like so:
+
You would add a ledge you would use this code:
<pre class="codebox"> <nowiki>$phpbb_dispatcher->dispatch('identifer', $input_param); </nowiki> </pre>
+
<php>
Let's dissect that code
+
$vars = array('arrayname');
 +
$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 />
  
<pre class="narrow-codebox"> <nowiki>$phpbb_dispatcher</nowiki></pre>
+
== Dissection ==
This is the phpbb_dispatcher object, which is automatically loaded with the page. This object registers the hook containers of found within hook files (in the hooks/*.php directory) with the hooks controller.
+
<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="narrow-codebox"> <nowiki>dispatch</nowiki></pre>
+
<pre class="codebox"> <nowiki>$event = new phpbb_event_data(compact($vars));</nowiki></pre>
This method adds a ledge.
+
This won't need any changes and is beyond the scope of this article.
 +
<br /><br />
  
<pre class="narrow-codebox"> <nowiki>identifer</nowiki></pre>
+
<pre class="codebox"> <nowiki>$phpbb_dispatcher->dispatch('identifier', $event);</nowiki></pre>
This is where you enter 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.
+
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. When its in a function you may need to add the following beforehand:
 +
<pre class="narrow-codebox"> <nowiki>global $phpbb_dispatcher</nowiki></pre>
 +
<br /><br />
  
<pre class="narrow-codebox"> <nowiki>$input_param</nowiki></pre>
+
<pre class="codebox"> <nowiki>extract($event->get_data_filtered($vars));</nowiki></pre>
This is where the input parameters go. This will either be a single variable or an array of variables, depending on the ledge onto which you are hooking.
+
This gets the data from the hook. This won't need changing.
 
+
<br /><br />
When required you will also need to add:
+
<pre class="narrow-codebox"> <nowiki>global $phpbb_dispatcher</nowiki></pre>
+
  
  
 
Based on the blog article [http://blog.phpbb.com/2010/10/09/explaining-hooks/ Explaining Hooks]
 
Based on the blog article [http://blog.phpbb.com/2010/10/09/explaining-hooks/ Explaining Hooks]
 
[[Category:Ledges and Hooks]]
 
[[Category:Ledges and Hooks]]

Revision as of 17:26, 12 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

You would add a ledge you would use this code:

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

Let's dissect that code

Dissection

 $vars = array('arrayvariable');

This just defines the variable vars as the variable for the array.

 $event = new phpbb_event_data(compact($vars));

This won't need any changes and is beyond the scope of this article.

 $phpbb_dispatcher->dispatch('identifier', $event);

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. When its in a function you may need to add the following beforehand:

 global $phpbb_dispatcher



 extract($event->get_data_filtered($vars));

This gets the data from the hook. This won't need changing.


Based on the blog article Explaining Hooks