Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

How to extend an existing plugin

lealea
edited March 2012 in Vanilla 2.0 - 2.8

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.

Tagged:

Best Answer

  • Options
    x00x00 MVP
    edited March 2012 Answer ✓

    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.

Answers

  • Options
    x00x00 MVP
    edited March 2012 Answer ✓

    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.

  • Options

    "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.

  • Options

    x00 said:
    In short you should just create another plugin that does what you want, make sure it is not in conflict with somethign else.

    Ok, I'll do that. Thanks.

  • Options
    x00x00 MVP
    edited March 2012

    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

    public function RegisterNewMethod($NewMethodClassName, $NewMethodName, $EventClassName = '', $EventName = '') {
        $NewMethodKey = $NewMethodClassName.'.'.$NewMethodName;
        $EventKey = strtolower($EventClassName == '' ? $NewMethodName : $EventClassName.'_'.$EventName.'_Create');
    
        // Throw an error if this method has already been created.
        if (array_key_exists($EventKey, $this->_NewMethodCollection) === TRUE)
            trigger_error(ErrorMessage('New object methods must be unique. The new "'.$EventKey.'" method has already been assigned by the "'.$this->_NewMethodCollection[$EventKey].'" plugin. It cannot also be assigned by the "'.$NewMethodClassName.'" plugin.', 'PluginManager', 'RegisterNewMethod'), E_USER_ERROR);
    
        // Otherwise, specify this class as the source for the new method.
        $this->_NewMethodCollection[$EventKey] = $NewMethodKey;
    }
    

    you can see it is not possible to do what you were trying to do.

    grep is your friend.

Sign In or Register to comment.