phpBB

Development Wiki

Difference between revisions of "Add Events"

From phpBB Development Wiki

(How to add an event to templates)
(Moved to new docs)
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==What are events?==
+
This documentation has been moved to the new phpBB Development Documentation.
An event is a hook location (also once known as a ledge). 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 events. For more information, see the wiki article for [[listeners]].
+
  
==How to add an event to everything except templates==
+
[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 an event you would use this code:
+
<php>
+
global $phpbb_dispatcher;
+
 
+
$vars = array('var1', 'var2');
+
extract($phpbb_dispatcher->trigger_event('identifier', compact($vars)));
+
</php>
+
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:
+
<php>
+
global $phpbb_dispatcher;
+
 
+
$phpbb_dispatcher->dispatch('identifer');
+
</php>
+
 
+
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.
+
 
+
==How to add an event to templates==
+
This is very simple to do
+
<pre><!-- EVENT identifier --></pre>
+
Just replace the identifier with the name of the listenr by just using underscores, numbers and lowercase letters.
+
 
+
And now you've made an event and just need to document it as below.
+
 
+
==Core events List==
+
If you add a events to the core you need to ensure you add it to the events list to ensure it remains a comprehensive and exhaustive list.
+
 
+
You can view and edit the events list page [[Events_List|here]]
+
 
+
==Examples of events being added==
+
* [https://github.com/p/phpbb3/commit/15e4bdd67f69844b8f7c2387196fa3c54b66ff7c core.memberlist_profile_data ledge.]
+
* [https://github.com/p/phpbb3/commit/7e3cc2a333b4969f69622620cfd7b08ae595a219 Display forum ledges]
+
 
+
[[Category:Events and Listeners]]
+

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.