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

Getting original arguments in override

edited March 2011 in Vanilla 2.0 - 2.8
I want to override few methods, some of the have aguments.

I understand how to make override method looking to http://vanillaforums.org/docs/plugins

But Plugin dispatcher calls function with $Sender argument instead of original method aruments.

Comments

  • Options
    SS ✭✭
    Arguments available in second parameter (array).

    public function UserController_AutoComplete_Create($Sender, $Arguments) {
    // $Sender->RequestArgs ~ $Arguments
    // list ($A1, $A2) = $Arguments;
    }
  • Options
    Interested. I don't see this in docs.
  • Options
    SS ✭✭
    Most docs outdated
    http://markosullivan.ca/garden-preview-part-viii-plugins/
    This entry was posted on Monday, December 29th, 2008 at 10:05 am and is filed under Garden
  • Options
    I see.
    But according to this doc I see that $Arguments are present in Events, but do not see them present in magic methods (I am interested in overrides).
  • Options
    LincLinc Detroit Admin
    edited March 2011
    _Override only works for Render (because it's named xRender), which doesn't have more arguments anyway.

    You can, however, use _Create to override an existing method (undocumented; more on that in a moment). In Models, the additional arguments will get passed as parameters I believe:

    UserModel_MethodName_Create($Sender, $Arg1, $Arg2, $Arg3)

    Called with: $UserModel->MethodName($Arg1, $Arg2, $Arg3);

    Conversely, Controllers get their arguments from the URL, which can be accessed with $Sender->RequestArgs inside plugins. That's clearly documented in the master controller (/library/core/class.controller.php).

    Overall, I tend to think if you're creating overrides then you're probably not approaching the problem right. Usually when I start with an override I end up rearranging it to use object inheritance or a fired event instead. Not always, but usually.

    If the _Create override hacky thing gets written up, I'd include strong wording about preferring fired events. Overriding means you lose additional functionality as it's released into core and could cause you a real headache down the line.

    You have to understand the Plugins doc page is written from the perspective of a thesis, not a guide to Plugin devs, because it was meant to get people excited about the idea back in '08. That's probably the 1 page of the docs I'd be most interested in re-writing as I think it's definitely costing us plugin developers.
Sign In or Register to comment.