XF 2.2 Class extension only functional with extreme execution order

Justis R

Member
Hey there, I’m just getting started with XF development and I’m both baffled and confused at the moment.

My understanding of the class extension system was that as long as your class extension has a higher execution order than all of the others, it’ll be executed last and therefore have the final say in the return value.

My website is using an addon (SV\ContentRatings) which overrides XF's ConversationMessage#reactionsCounted implementation to return true rather than false. This wasn’t configurable, so I made my own class extension on the same XF class to change the return value back to false and set my execution order to be higher.

Theirs was 3, so I expected 10 to work, but it didn’t. The reactions were still counting. I upped mine to 100, no change. Upped it to 1,000, no change. Upped it to 10,000 and suddenly the reactions weren’t being counted. It seems my extension is finally having the final say.

I reduced it back down and up again and had the same results.

This goes against what I understood about the class extension system, so I was hoping someone could help shed some light on what’s happening here.
 
Did you ever figure this out?
Edit: the reason I ask is that I've just been tearing my hair out with a somewhat related issue.

In short, I have been trying to extend an extension, and I'm starting to think that this isn't possible.

I've put together three extensions in my very simple addon, two of which extend classes which are not themselves set up as "class extensions" in the ACP, and both of those work.
The third is an extension of a class in an addon (also from SV funnily enough), and that class is already set up as an extension of an XF View class. I cannot get it work at all. I then had the idea of just attempting to extend the base class instead, at which point I guess I'm basically fighting with the SV addon about which extension is run. When my execution order was set lower than the one used by the SV class extension, the Composer did actually read my code (I know this because when I put garbage in the file, I got an error), but it didn't then execute it. As soon as I raised my execution order above the SV value, my code was executed (yay) but I am now presuming that I have lost the ability to simply call the parent and have it run parts of the SV class...

If any XF gurus are reading this, is it in fact impossible to extend an existing class extension? If it's possible I am clearly doing something wrong, but all three of my extensions are set up "the same"
:cry:

Doh. I finally hit on the stupendously clever concept of actually checking if the "parent" was the base class or the SV class. Turns out it was the SV class after all (yay again). So I am inferring, rightly or wrongly, that the correct way to extend an extension is to extend the base class and then pick a higher execution order than the existing class extension. Still puzzled about why I can't simply extend the extension itself but I guess there'll be a good reason! 😬
 
Last edited:
Using a non-default execution order was required on older versions of XenForo, as before if they shared the same execution order id the sort order would be install order dependent. When a large number of add-ons are installed all extending similar things, this is a compatibility nightmare.

Generally I use the XenForo Resource Manager resource id for the execution order so they are stable and predictable. Every so often I need to change the order, but that is the exception.

Doh. I finally hit on the stupendously clever concept of actually checking if the "parent" was the base class or the SV class. Turns out it was the SV class after all (yay again). So I am inferring, rightly or wrongly, that the correct way to extend an extension is to extend the base class and then pick a higher execution order than the existing class extension. Still puzzled about why I can't simply extend the extension itself but I guess there'll be a good reason! 😬
When extending classes you need to extend the base class not the extended class.
 
When extending classes you need to extend the base class not the extended class.
Hey, a reply from the author of the addon I'm extending :D - much appreciated.
Thanks for confirming that (and thanks also for the great addons).
Is this written down in the dev docs? If so I must have missed it.
Generally I use the XenForo Resource Manager resource id for the execution order so they are stable and predictable. Every so often I need to change the order, but that is the exception.
Perhaps I'm simply experiencing the exceptional case then.

I'm extending one of your classes which itself extends another class, and moreover I'm extending (wrong terminology maybe?) the same function that your class extends/overrides. Also, in this instance, since the function I'm extending doesn't call its parent in the specific case I'm most interested in, I think I have no option other than to adjust the order so that my class has a higher execution order than yours.

Thinking about it though, I guess it may often be the case that class extensions don't touch the same functions, or do so in a way that doesn't depend on execution order.
 
Using a non-default execution order was required on older versions of XenForo, as before if they shared the same execution order id the sort order would be install order dependent. When a large number of add-ons are installed all extending similar things, this is a compatibility nightmare.

Generally I use the XenForo Resource Manager resource id for the execution order so they are stable and predictable. Every so often I need to change the order, but that is the exception.


When extending classes you need to extend the base class not the extended class.
Are you saying that even though the class extension execution order appears as 3 within the ACP, you’re somehow giving the extension a differing priority somewhere that I’m not seeing?

If so, where might I find where that is determined and applied?
Is that something you’ve seen other addon developers do as well?
 
I'm extending one of your classes which itself extends another class, and moreover I'm extending (wrong terminology maybe?) the same function that your class extends/overrides. Also, in this instance, since the function I'm extending doesn't call its parent in the specific case I'm most interested in, I think I have no option other than to adjust the order so that my class has a higher execution order than yours.
Correct. If you are extending stuff you will almost always want you have a higher execution order as this means your function is called first. This allows you to setup before calling the parent and after getting any result.

I've got a couple add-on which use the execution order of 2^31, as they are highly invasive in how they extend classes and need to always run first.

Are you saying that even though the class extension execution order appears as 3 within the ACP, you’re somehow giving the extension a differing priority somewhere that I’m not seeing?
In the admincp, class extensions are grouped and sorted by add-on and then sorted by execution order.
When class extensions are applied, they are sorted by execution order and then by add-on id.

You basically need to manually check the class extension to see what execution order it has as the GUI is misleading. This is why I try to consistently have the same scheme for the execution order id, as the sites I run have about 100 add-ons installed and it isn't unusual for some classes to be extended by half a dozen add-ons at once.
 
Correct. If you are extending stuff you will almost always want you have a higher execution order as this means your function is called first. This allows you to setup before calling the parent and after getting any result.

I've got a couple add-on which use the execution order of 2^31, as they are highly invasive in how they extend classes and need to always run first.


In the admincp, class extensions are grouped and sorted by add-on and then sorted by execution order.
When class extensions are applied, they are sorted by execution order and then by add-on id.

You basically need to manually check the class extension to see what execution order it has as the GUI is misleading. This is why I try to consistently have the same scheme for the execution order id, as the sites I run have about 100 add-ons installed and it isn't unusual for some classes to be extended by half a dozen add-ons at once.
Looks like SV\ContentRatings\XF\Reaction\ConversationMessage actually had an execution order of 5600 set. I must have mistakenly been looking at SV\ContentRatings\XF\Entity\ConversationMessage which has a priority of 3. So this thread’s question was actually just due to a misunderstanding on my part.
 
Back
Top Bottom