GanstaZ wrote: Sun Dec 03, 2023 7:46 pm
If anyone wants to have a way to sort template events, it can be implemented easily. It's more about "do admins need to have that power"?
Based on discord.. Toxyy was/is working on that sorting part.
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
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'
]
if your priority is `2`, then it will be placed as so:
Code: Select all
[
'0' => 'first_event',
'1' => 'second_event',
'2' => 'priority_set_event',
'3' => 'third_event',
'4' => 'fourth_event'
]
And then if another event has a priority of `2`, then it will be placed above it:
Code: Select all
[
'0' => 'first_event',
'1' => 'second_event',
'2' => 'another_priority_set_event',
'3' => 'priority_set_event'.
'4' => 'third_event',
'5' => 'fourth_event'
]
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.