Skip to content

Commit a30511f

Browse files
committed
Address review issues.
1 parent ca4d3b7 commit a30511f

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

development/extensions/tutorial_events.rst

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,15 @@ text ``DEMO_PAGE``. We will fix the link text in the next section.
8383
look for template listeners when a page is being rendered.
8484

8585
Prioritising template event listeners (optional)
86-
---------------------------------------
87-
88-
In rare cases, some extensions could cause a conflict when template listeners
89-
from different extensions are subscribed to the same template event. In such cases
90-
phpBB allows to assign the priority to template event listeners, which allows
91-
to determine the order template event listeners will be compiled.
92-
This can be accomplished using PHP core event listener subscribed to the
93-
``core.twig_event_tokenparser_constructor`` core event, which should use
94-
``template_event_priority_array`` array variable to assign the template event listener priority.
95-
``template_event_priority_array`` array has the following format:
86+
------------------------------------------------
9687

97-
::
88+
In rare cases, conflicts may occur when multiple extensions subscribe to the same template
89+
event using template listeners. To resolve such conflicts, phpBB allows you to control the
90+
order in which template event listeners are compiled by assigning them priorities.
9891

99-
'<vendor>_<name>' => [
100-
'event/<template_event_name>' => <priority_number>,
101-
],
92+
This is done by subscribing a PHP event listener to the
93+
``core.twig_event_tokenparser_constructor`` event and using the
94+
``template_event_priority_array`` variable to define listener priorities.
10295

10396
Example:
10497

@@ -112,38 +105,32 @@ Example:
112105
113106
class main_listener implements EventSubscriberInterface
114107
{
115-
/**
116-
* Assign functions defined in this class to event listeners in the core
117-
*
118-
* @return array
119-
*/
108+
// Subscribe an event listener function to the core.twig_event_tokenparser_constructor
120109
static public function getSubscribedEvents()
121110
{
122111
return [
123112
'core.twig_event_tokenparser_constructor' => 'set_template_event_priority',
124113
];
125114
}
126115
127-
/**
128-
* Assign priority to template event listener
129-
*
130-
* @param \phpbb\event\data $event The event object
131-
*/
116+
// Give your extension a high priority when rendering the navbar_header_quick_links_after template event.
132117
public function set_template_event_priority($event)
133118
{
134119
$template_event_priority_array = $event['template_event_priority_array'];
135120
$template_event_priority_array['acme_demo'] = [
136-
'event/navbar_header_quick_links_after' => $priority,
121+
'event/navbar_header_quick_links_after' => 100,
137122
];
138123
$event['template_event_priority_array'] = $template_event_priority_array;
139124
}
140125
}
141126
142-
In this example, ``$priority`` is an integer, the value of which defaults to 0.
143-
Setting this integer to higher values equals more importance and therefore that
144-
template event listener will be compiled earlier than others subscribed to the same template event.
145-
In case of equal priority values, template event listeners will be compiled in the order
146-
they have been read from their locations.
127+
In this example, ``100`` is an integer implying the template event priority. Higher values
128+
indicate greater importance, meaning the corresponding template event listener
129+
will be compiled earlier than others listening to the same event.
130+
For example, the content of template event listener which has a priority value of ``100``
131+
will be rendered above/before the same template event listener which has a priority value of ``99``.
132+
If multiple listeners share the same priority value, they will be rendered in the order they were read
133+
from their respective filesystem locations. If no priority value set, it defaults to ``0``.
147134

148135
PHP Core Events & Listeners
149136
===========================

0 commit comments

Comments
 (0)