Sortable extension events

Note: We are moving the topics of this forum and it will be deleted at some point

Publish your own request for comments/change or patches for the next version of phpBB. Discuss the contributions and proposals of others. Upcoming releases are 3.2/Rhea and 3.3.
spencer4678
Registered User
Posts: 1
Joined: Wed May 03, 2017 1:02 am

Ability to specify load order of extensions

Post by spencer4678 »

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

rubencm
Development Team
Development Team
Posts: 32
Joined: Sun Mar 12, 2017 8:30 pm
Location: h[b]ell[/b]o

Re: Ability to specify load order of extensions

Post by rubencm »


User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 1904
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth
Contact:

Re: Sortable extension events

Post by DavidIQ »

Merged both topics.
Image

User avatar
Toxyy
Registered User
Posts: 8
Joined: Thu Aug 02, 2018 9:15 am

Re: Sortable extension events

Post by Toxyy »

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;
}
Image

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.

Post Reply