How to extend an existing plugin
Hi all,
I'm completely new to vanilla forum and I'd like to extend the ProxyConnect plugin. Now I'm already stuck with how to best extend an existing plugin. What I did:
I created a new plugin and added a php file with the plugin information and the class definition, where I extend the ProxyConnectPlugin class.
The problem now is the following: when enabling my plugin I get the error, that the class ProxyConnectPlugin does not exist, which is due to the ProxyConnect plugin not being enabled.
If I however enable both plugins I get the following error:
"New object methods must be unique. The new "settingscontroller_proxyconnect_create" method has already been assigned by the "ProxyConnectPlugin.settingscontroller_proxyconnect_create" plugin. It cannot also be assigned by the "MyProxyConnectPlugin" plugin.|PluginManager|RegisterNewMethod|"
So, is there a best way to extend an existing plugin? Thanks for your help.
Best Answer
-
x00 MVP
this is basic php, the clue is in the error. I think you should start with somethign simpler first.
We offer help but not programming tuition.
In short you should just create another plugin that does what you want, make sure it is not in conflict with somethign else.
If you were to extend the functionality of a plugin, then the plugin would either need hooks, or you need to do it in a complementary way that does not override, or you could be using some static methods, etc, or use its own model or other stuff that is available.
grep is your friend.
0
Answers
this is basic php, the clue is in the error. I think you should start with somethign simpler first.
We offer help but not programming tuition.
In short you should just create another plugin that does what you want, make sure it is not in conflict with somethign else.
If you were to extend the functionality of a plugin, then the plugin would either need hooks, or you need to do it in a complementary way that does not override, or you could be using some static methods, etc, or use its own model or other stuff that is available.
grep is your friend.
"the clue is in the error" that's not very helpful. just please point me to a best practice of how to extend vanilla plugins. I know how to extend php classes, but obviously there's something more here with the plugins. I mean, I don't want to enable them both, I only want to enable the one extending the ProxyConnect plugin. But that does not seem possible because then the class I want to extend is not loaded. So how would you usually extend an existing plugin? Or do you just copy paste the whole plugin and put in your changes? If that's the way to go, just say so and that's ok. I'd just prefer a solution where I can keep the original plugin as it is and just base my changes on it.
Ok, I'll do that. Thanks.
magic method cannot be doubled up, they are proxy controller methods, in a RESTful system that would have the same uri. technically you could include any class yourself, but you are going to get into a whole lot of mess. The primary purpose of plug in is as an container for hooks.
if you look in
core/class.pluginmanager.php
you can see it is not possible to do what you were trying to do.
grep is your friend.