Class extension criteria

TickTackk

Well-known member
XenForo 2.2 bought loads of changes to the core which required updating parameters a method uses, changing the class hint in methods and even more changes. This change broke many add-ons in a way that add-on developer will have either drop support for XF 2.1 and lower or using class_alias like here. Using class_alias works but is very hacky and things don't quite look "clean".

Being able to set class extension criteria to only apply when the X, Y and Z add-ons are installed and those add-ons min/max version match will greatly help in maintaining compatibility between older and future second-point XF/add-ons releases.

The reason why I'm asking to support setting multiple add-ons is so something like this could work for Covers by TH:
  1. Do a version bump
  2. For the class extension XF\Pub\Controller\Thread to only apply when the version compare is less than 2020010 for add-on XF
  3. Change the extension class to TH\Covers\XF22\Pub\Controller\Thread
then I can update my add-on which extends the action added by the Covers add-on to add new feature/permission/all that fancy stuff to:
  1. Do a version bump
  2. For the class extension XF\Pub\Controller\Thread to only apply when the version compare is less than 1000471 for add-on TH\Covers
  3. Change the class extension to TickTackk\THCoversExtension\XF21\Pub\Controller\Thread
  4. Add a new class extension for XF\Pub\Controller\Thread with class extension set to TickTackk\THCoversExtension\XF22\Pub\Controller\Thread to only apply when version compare is equal to or greater than 2020010 for add-on XF
  5. Move the parts of action from the original extension class into a trait
  6. Update both the original class extension and the newly added extension to make use of the trait added in previous state

(writing suggestions is hard)
 
Upvote 10
Just found out another limitation of using class_alias, the method \XF\Extension::resolveExtendedClassToRoot does not seem to be able to resolve the aliased class back to the original class name. This becomes obvious on the Current visitors page, where the current page is shown based on the controller, and for that the name of the controller should be resolved back to the original class name when updating user's session activity.

My solution for now is to modify the container and put my own class instead of \XF\Extension to replace the method resolveExtendedClassToRoot and use regular expressions to remove XF21/XF22 from the name of the class, which restores the original name of the extended class and XF correctly resolves it back to the source class name.
 
Top Bottom