If you have two extensions that hook into the same template event, it is likely desirable to be able to specify which one should load and appear before the other.
https://tracker.phpbb.com/browse/PHPBB3-15214
Sortable extension events
-
- Registered User
- Posts: 1
- Joined: Wed May 03, 2017 1:02 am
Re: Sortable extension events
Just PRd a proof of concept
https://github.com/phpbb/phpbb/pull/6571
If approved, you could add priority to template events by hooking into the
Example event usage:
With this, my template event is called before any others. Normal behavior would have it placed on the bottom of this list.
As stated in the commit message, priority works like in Symfony events, the higher number will be compiled first.
If two events have the same priority, then the last one added will be executed last - this differs from what's stated in my initial commit message, sorry about that, I was thinking about it wrong.
Reason being is that for an array:
if your priority is `2`, then it will be placed as so:
And then if another event has a priority of `2`, then it will be placed above it:
And because the higher numbers get executed first (krsort), it will get compiled after the previously set template event for the same priority. This is an edge case though. Not sure how Symfony handles this. Template events by default are parsed in alphabetical order by extension namespace. If no one uses the event, then template events will execute in the same order as they do now.
https://github.com/phpbb/phpbb/pull/6571
If approved, you could add priority to template events by hooking into the
twig_tokenparser_constructor
(name of event TBD) event in a listener.Example event usage:
Code: Select all
public function twig_tokenparser_constructor($event)
{
$template_event_priority_array = $event['template_event_priority_array'];
$template_event_priority_array += [
'toxyy_postformtemplates' => [
'event/overall_header_head_append' => 1000
]
];
$event['template_event_priority_array'] = $template_event_priority_array;
}
With this, my template event is called before any others. Normal behavior would have it placed on the bottom of this list.
As stated in the commit message, priority works like in Symfony events, the higher number will be compiled first.
If two events have the same priority, then the last one added will be executed last - this differs from what's stated in my initial commit message, sorry about that, I was thinking about it wrong.
Reason being is that for an array:
Code: Select all
[
'0' => 'first_event',
'1' => 'second_event',
'2' => 'third_event',
'3' => 'fourth_event'
]
Code: Select all
[
'0' => 'first_event',
'1' => 'second_event',
'2' => 'priority_set_event',
'3' => 'third_event',
'4' => 'fourth_event'
]
Code: Select all
[
'0' => 'first_event',
'1' => 'second_event',
'2' => 'another_priority_set_event',
'3' => 'priority_set_event'.
'4' => 'third_event',
'5' => 'fourth_event'
]