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.

How to remove a module from an existing controller

LincLinc Detroit Admin
edited July 2010 in Vanilla 2.0 - 2.8
Hey @Todd, if I wanted to remove the NewDiscussion (or any) module from the Discussion's Index method, how could I do that with a plugin or theme? I see no RemoveModule function which would've been my best guess.

Comments

  • LincLinc Detroit Admin
    edited July 2010
    Ah HA, the Controller's Assets are public! Answer:
    public function DiscussionController_BeforeDiscussionRender_Handler(&$Sender) {
    unset($Sender->Assets['Panel']['NewDiscussionModule']);
    }
  • ToddTodd Chief Product Officer Vanilla Staff
    You got it better than me.
  • peregrineperegrine MVP
    edited July 2013

    @Lincoln said:
    Ah HA, the Controller's Assets are public! Answer:public function DiscussionController_BeforeDiscussionRender_Handler(&$Sender) {
    unset($Sender->Assets['Panel']['NewDiscussionModule']);
    }

    • anything you know of offhand for Vanilla 2.1.
      (in my case, specifically removing the SidemenuModel).

    presently hiding module in css works, but removing a module would be a nice feature, if it isn't already implemented.

    It's a necropost but its still the same question!

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited July 2013

    I see no RemoveModule function which would've been my best guess.

    I have used this to remove modules and used AddModule to add ... :)

    css is a good alternative I think .

    $this->Head-> RemoveModule('ElModulo');

    peregrine
  • peregrineperegrine MVP
    edited July 2013

    @vrijvlinder said:

    I see no RemoveModule function which would've been my best guess.

    css is a good alternative I think .

    thx for the reply. Unfortuantely I wasn't looking for imaginary things.
    removing via css is not the best thats why I stated what I did. :)

    I have used this to remove modules and used AddModule to add ... :)
    $this->Head-> RemoveModule('ElModulo');

    what is this? Did you specifically remove modules in 2.1 with the imaginary function that doesn't exist.
    Did you actually see that "$this->Head-> RemoveModule('ElModulo');" or are you just posting imaginary stuff again :)

    I know i could override function.

    But the statement that lincoln posted for previous version would be nice if it worked in vanilla 2.1.

    Hoping someone in the know would know, and was hoping to avoid imaginary things.

    But it's not crucial for what I am doing.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • hgtonighthgtonight ∞ · New Moderator

    Modules are just assets in an asset container which are part of a controller.

    Assets get rendered when the asset container is rendered.

    Unsetting the asset before rendering should do what you need.

    public function Base_Render_Before($Sender) {
      unset($Sender->Assets['Panel']['SideMenuModule']);
    }
    

    Of course you would want to put a conditional in there if you only want to remove it on some pages. I just tested this on a local dev environment.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    vrijvlinderperegrineShadowdare
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Did you specifically remove modules in 2.1

    no it worked on 2.0 , I guess the method needs to be there to be able to apply it. sorry ...

  • peregrineperegrine MVP
    edited July 2013

    @hgtonight said:
    Modules are just assets in an asset container which are part of a controller.

    Assets get rendered when the asset container is rendered.

    Unsetting the asset before rendering should do what you need.

    public function Base_Render_Before($Sender) {
      unset($Sender->Assets['Panel']['SideMenuModule']);
    }
    

    Of course you would want to put a conditional in there if you only want to remove it on some pages. I just tested this on a local dev environment.

    thanks hg - proof that what lincoln suggested it works in 2.1 for the Base_Render_Before

    But in my case the module in question is added later. :) So it is still too early at that point. I'll experiment thanks. At least I know unset works for modules added prior to
    Render_Before. and I haven't found an event where I can unset later, even directly after profile controller method getuserinfo is called in my create function. So maybe I'll emulate getuserinfo and solve the issue.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • hgtonighthgtonight ∞ · New Moderator
    edited July 2013

    @peregrine said:
    But in my case the module in question is added later. :) So it is still too early at that point.

    Consider my curiosity peeked. How does one load a module after rendering?

    Through JS?

    EDIT - Glad my 1000th comment was about learning something :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    UnderDogperegrineSudoCat
  • LincLinc Detroit Admin
    edited July 2013

    It's generally not good practice to load up Base_Render_Before. It's the laziest hook, and because events do not prioritize order of hooks, you can get into a mess real quick (plus there's the performance hit of needlessly firing it on every. single. page.) It's really a last-resort hook, and perhaps means you should look at adding an event to core somewhere (or look harder for the right one).

    Whatever is adding a module past Base_Render_Before is probably doin' it wrong. ;)

    (This is the part where you tell me it's something I wrote doing it...)

  • hgtonight set me straight! His eyes are 20/20

    the problem was getuserinfo loaded a module in my plugin create routine

    based on EditMode(FALSE) or TRUE different modules get added

    I had so many iterations of testing things
    I just put EditMode(FALSE) in the wrong place and assumed it didn't work.

    my logic was a moving target. I narrowed down to getuserinfo loading the module (except not the one I wanted. I tried a test but put the EditMode(FALSE) after the getuserinfo call (duh!). or in other events that didn't pertain, so i got it resolved.

    I try to use the Profile Discussion or whatever instead of base. I suppose that cuts down a little but still hits all the assets in the page.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.