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 prevent duplication when overriding an event handler?

pavsidpavsid New
edited May 2016 in Vanilla 2.0 - 2.8

Hi, i need to override ProfileController_AfterUserInfo_Handler in YagaHooks, but if I do this then both handlers are called.

Is there any way to prevent the original handler being called? I'm using 2.2.

Thanks

Best Answer

Answers

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    You cannot "override" that. Every plugin, addon, theme can use this event to add content and no usage will block the others.

    You might be able to trick something, though...

    The code in YAGA starts like that:

      public function ProfileController_AfterUserInfo_Handler($Sender) {
        if(!C('Yaga.Reactions.Enabled')) {
          return;
        }
    

    So if you manage to hook into ProfileController_AfterUserInfo before YAGA, you could set the setting 'Yaga.Reactions.Enabled' temporarily to false (saveToConfig('Yaga.Reactions.Enabled', false, false)) and you are done.

    What sounds easy might become a problem: I guess addons are executed before plugins and so you would have to write an addon instead. I don't know if themehooks run before or after addons so you can test if a custom theme would do the trick.

    And if there is other YAGA content on that page, it might get disabled. So you would have to use the event YAGA hooks for such a second display, and "reenable" the config setting. All in all it is a quite ugly workaround.

    It might be cleaner in this case to hide YAGAs div.Yaga.ReactionsWrap on this page with a CSS display:none rule

  • Options
    hgtonighthgtonight ∞ · New Moderator

    What are you looking to accomplish?

    You could potentially extend the YagaHooks class, override the method, and deregister the original YagaHooks via a really early startup hook.

    Perhaps there is an easier way if you discuss why you want to do this.

    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.

  • Options
    pavsidpavsid New
    edited May 2016

    Hi both, thanks for your answers. All i really need to do is wrap another div around div.DataCounts!!

    In order to style it better for small screens.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    I could/should split this out into a module with a view, then you could override the view easily. Perhaps an enhancement for 1.2.

    That said, why would you need another div? That smells like a bad idea.

    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.

  • Options
    pavsidpavsid New
    edited May 2016

    @hgtonight said:
    I could/should split this out into a module with a view, then you could override the view easily. Perhaps an enhancement for 1.2.

    That said, why would you need another div? That smells like a bad idea.

    So users on mobile devices can scroll sideways through the "reactions" by setting overflow-x:scroll on the outer div. I've styled them differently like so...

    It's not vital, i'm probably safer just going with @R_J 's suggestion of hiding the other div via CSS

  • Options

    @Bleistivt - oh yeh....!! Thanks :+1:

Sign In or Register to comment.