Priority event extensions

Discussion forum for Extension Writers regarding Extension Development.
User avatar
bennybernaer
Registered User
Posts: 633
Joined: Tue Mar 22, 2011 9:53 pm

Priority event extensions

Post by bennybernaer »

I don't know if I'm writing in the right place here, but if not, please move my topic.

If I now use extensions with the same event, and that code must be displayed in the same place, it is often displayed in the installation sequence.

Back in the days of modifications, if I installed a mod and those modifications were installed in the same place, I as a user could actually choose in which order it should be displayed. (You actually just had to change the code to determine the next modifications).

If you now place an extension under ({% EVENT viewtopic_body_online_list_before %} you don't have that choice at all...

Or am I seeing this completely wrong
User avatar
GanstaZ
Registered User
Posts: 1188
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Priority event extensions

Post by GanstaZ »

There is no way to set order for template events.. at least not the way as you mentioned above.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
Sniper_E
Registered User
Posts: 1163
Joined: Wed May 09, 2007 12:18 am
Location: Shreveport, Louisiana
Name: Ed Humphrey

Re: Priority event extensions

Post by Sniper_E »

bennybernaer wrote: Thu Nov 30, 2023 4:22 pmIf I now use extensions with the same event, and that code must be displayed in the same place, it is often displayed in the installation sequence.
Or am I seeing this completely wrong?
These guys may correct me but I noticed over 2 years ago the the extensions load up in order of the name not in the order they were installed.
First "Board Attachments" then "mChat" then "Quick Reply Reloaded" and finally "Upload Extensions"

Edit: I take that back, just looked again and they load by vender name not the extension name. My memory was off a little.

In your index page right click on the body and select View Page Source and you will see the order that the extension's css loads.
Image . -.. / .... ..- -- .--. .... .-. . -.--
No is NEVER an Option and NEVER is the only Option when it comes to Giving Up!

:!: Sniper_E Styles | phpbbmodders :!:
User avatar
Mike-on-Tour
Registered User
Posts: 488
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: Priority event extensions

Post by Mike-on-Tour »

Sniper_E wrote: Thu Nov 30, 2023 5:18 pm I take that back, just looked again and they load by vender name not the extension name.
That's my observation, too.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
rxu
Extensions Development Team
Posts: 3771
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: Priority event extensions

Post by rxu »

Actually they load in order the data got selected from the DB extensions table https://github.com/phpbb/phpbb/blob/mas ... hp#L88-L89
As far as the SQL query doesn't contain ORDER BY clause, resulting order can differ on different DBMS versions/servers/installations etc.
But what is certain is that currently it's impossible for extensions to choose an order template events load.
User avatar
danieltj
Jr. Extension Validator
Posts: 312
Joined: Thu May 03, 2018 9:32 pm
Location: United Kingdom
Name: Daniel James

Re: Priority event extensions

Post by danieltj »

Extensions need to mirror how WordPress does it. You can choose the order by changing a priority number in the action or filter hook. Extensions are very primitive in their lifecycle at the moment.
Extensions Developer
Available for premium extension development (PM me).
User avatar
GanstaZ
Registered User
Posts: 1188
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Priority event extensions

Post by GanstaZ »

Primitive? I would say limited, because of current phpBB (3.3.x) branch.

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.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
Toxyy
Registered User
Posts: 958
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek

Re: Priority event extensions

Post by Toxyy »

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;
}
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.
I am a web developer/administrator, specializing in forums. If you have work you need done or are too lazy to do, pm me!

Some of my extensions:
[3.3][BETA] Post Form Templates || [3.3][BETA] Anonymous Posts || [3.2][3.3][BETA] ACP Merge Child Forums || [3.2][BETA] Sticky Ad || [3.2][DEV] User Delete Topics || [3.3][DEV] Moderate While Searching || [3.3][RC] Short Number Twig Extension

Return to “Extension Writers Discussion”