1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Override view helper?

Discussion in 'XenForo Development Discussions' started by Liam W, Jun 8, 2013.

  1. Liam W

    Liam W Well-Known Member

    Is there a way I could override/extend a view helper class?

    I tried using the load_class_view but it doesn't seem to be working...
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Which class specifically?
     
  3. Liam W

    Liam W Well-Known Member

    XenForo_ViewPublic_Helper_Message
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    No, you can't, unfortunately.

    Can you do what you need to do by extending the classes which call it?
     
  5. Liam W

    Liam W Well-Known Member

    Yes, I guess. Dunno if it is technically the right way to do it though - I would have to make it use my class instead of xenForo's class - would that be OK?
     
  6. xf_phantom

    xf_phantom Well-Known Member

    That's why the event load_class_view is for;)
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    Not really.

    That has the potential to clash with other add-ons wanting to do similar things. If it's the absolute only way you can do it then there's perhaps not many other options.

    You could share here what you're trying to do then me or someone else might be able to tell you if there's other ways to achieve it.
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    Which can't be used to extend a XenForo_ViewPublic_Helper_XXXX class
     
    xf_phantom likes this.
  9. xf_phantom

    xf_phantom Well-Known Member

    Yea, sorry, i hadn't seen that it's really the helper what he's asking for.
     
    Chris D likes this.
  10. xf_phantom

    xf_phantom Well-Known Member

    and @Liam W don't forget to call the parent method!
    ATM your sig addon will break all other addons which are overriding the same view classes because they won't be called.
     
  11. Liam W

    Liam W Well-Known Member

    Added in for the next version....

    (Does it matter where the parent call goes? I added it at the top.)
     
  12. xf_phantom

    xf_phantom Well-Known Member

    In this case not really but there are several scenarios, where it matters.

    e.g. controller actions, model methods, etc.....


    the views are really special because there's not allways a real view class... many views are just fakes, so you can't call parent::renderHtml without checking if it's callable, see also this problem http://xenforo.com/community/threads/renderhtml-in-fakebase-classes.48133/
     

Share This Page