Extensions's event override.

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Extensions's event override.

Post by 3Di »

Two extensions, both mine, use the same event and modify the same SQL line.

To make one of the two extensions override the other at this point I use:

Code: Select all

	static public function getSubscribedEvents()
	{
		return array(
			'core.viewforum_get_announcement_topic_ids_data'	=> array('tcs_viewforum_get_announcement_topic_ids_data', -1,),
		);
	}
It does the trick. Is this method valid for validation?
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Extensions's event override.

Post by kasimi »

If you mean the negative priority then yes, it's perfectly valid.

Depending on what makes more sense in your situation, the other solution would be to give the event handler you quoted a priority of 0 (default) and give the other extension's handler a priority greater than 0.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Extensions's event override.

Post by 3Di »

kasimi wrote: Mon Oct 29, 2018 7:12 pm If you mean the negative priority then yes, it's perfectly valid.

Depending on what makes more sense in your situation, the other solution would be to give the event handler you quoted a priority of 0 (default) and give the other extension's handler a priority greater than 0.
Thanks.
Yeah, I went to that way first then I preferred to not modify an already validated extension just to add a priority to it. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
Toxyy
Registered User
Posts: 938
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: Extensions's event override.

Post by Toxyy »

kasimi wrote: Mon Oct 29, 2018 7:12 pm If you mean the negative priority then yes, it's perfectly valid.

Depending on what makes more sense in your situation, the other solution would be to give the event handler you quoted a priority of 0 (default) and give the other extension's handler a priority greater than 0.
How do you add priority to an event in your extension?

What if two extensions have the same priority for it?
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
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Extensions's event override.

Post by kasimi »

3Di showed an example in the first post, note the -1.

If two events have the same priority, they are executed in the order of inclusion (service.yml), though that's something you shouldn't rely on.
User avatar
Toxyy
Registered User
Posts: 938
Joined: Mon Oct 24, 2016 3:22 pm
Location: Namek
Contact:

Re: Extensions's event override.

Post by Toxyy »

kasimi wrote: Mon Oct 29, 2018 8:37 pm 3Di showed an example in the first post, note the -1.

If two events have the same priority, they are executed in the order of inclusion (service.yml), though that's something you shouldn't rely on.
Thanks. I was just considering that two extensions could have the same priority level and what to do in that case.
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
Post Reply

Return to “Extension Writers Discussion”