XF 2.1 How can an add-on be altered by another add-on?

Feanor

Active member
Is it possible to change a method in an add-on by another add-on? For example, if I have an add-on developed by someone else and I want to change a line of code in one of their PHP classes, what is the best way to do this?
 
You would just need to simply change it and then recompile with php cmd.php xf-addon:build-release AddonIDHere

You should probably also update the version number which you can do by changing the json file in the main directory. Simply change the version ID and version itself and then type this command. php cmd.php xf-addon:sync-json

After that then recompile. I just use the built in XAMPP command line and cd to the Xenforo directory. I have /src pulled up in PHPStorm and then simply use the commands like that.
 
You would just need to simply change it and then recompile with php cmd.php xf-addon:build-release AddonIDHere
Trying to avoid that so I don't have to compile someone else's add-on and also trying to avoid making the changes every time the add-on is updated by the developer. Is there a way to create a separate add-on that essentially overwrites their PHP method?
 
Trying to avoid that so I don't have to compile someone else's add-on and also trying to avoid making the changes every time the add-on is updated by the developer. Is there a way to create a separate add-on that essentially overwrites their PHP method?

I mean it works to change a line of code without re-compiling it but it will not last between updates and will be deleted after each one. So you would need to re-change it after each update. But besides giving you a file health check error saying the odd contents in one of your files, it does work. I would not recommend that though.
 
I think you can create a class extension for the add-on class, and overwrite it or only the method you'd like to change by using your own class. Just like you would do that for extending a core XenForo class. It should work without problems.
 
So just to verify: Let's say there's an add-on with class A. I extended it with my own add-on's class B. When the original add-on goes to use class A elsewhere in its code, does it now use my class B instead?
 
If you use the class extension system as described by the developer docs linked above, yes (again, assuming the class is run through the extension system).
 
Is this an option, the Coder need to force or he can deny?
It is something that must be handled during instantiation:

PHP:
$class = \XF::extendClass('Vendor\AddOn\Class');
$object = new $class();

Most objects instantiated by the framework are run through the class extension system.
 
It is something that must be handled during instantiation:

PHP:
$class = \XF::extendClass('Vendor\AddOn\Class');
$object = new $class();

Most objects instantiated by the framework are run through the class extension system.
Okay. So this is only needed when I am not using standard XF Technology like the Controllers or Services, only instead of using simple new.
 
Back
Top Bottom