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

Can I extend XenForo_Link, if so what listener do I need to use

Discussion in 'XenForo Development Discussions' started by tenants, Jan 2, 2012.

  1. tenants

    tenants Well-Known Member

    (Sorry in advance for typos, I've come to a coffee shop to ask this)

    When you navigate to index.php?find-new/id/threads, this uses the Route Prefix to go to XenForo_ControlerPublic_FindNew::actionThreads()

    actionThreads then redirects you to the find_new_threads template (with relevant params), this template contains the template thread_list_item.

    Within thread_list_item there exist links such as:
    <a href ={xen:link threads/unread, $thread}>

    I would like to redirect some of these links (given a particular condition)
    <a href ={xen:link some_url}>

    But to do this, I would need to extend actionThreads() to redirect to a new version of find_new_threads that contains a new version of thread_list_item, which then changes the links given the condition..

    This would be a bit messy, and not ideal since I would be creating my own version of the find_new_threads template which is core XenForo (others plug-ins might also want to use this area)

    There doesn't seem to be a way for switching the links using template hooks, there are no template hooks in thread_list_item I can use to switch the links, and there is no template hook in find_new_threads

    What I would prefer to do is extend XenForo_Link...
    (I know this works if I change the core files, but obviously can't do that for a plug-in). Also, if I can extend XenForo_Link, then it would solve my problem in all areas:
    if the link contains "threads/" and is from a certain forum .. then change the link to something else

    The problem is, it doesn't seem to be one of the listeners I can extend, I've tried all the Load_class_listeners with no luck.

    What listener should I be using to extend XenForo_Link?
     
  2. Fuhrmann

    Fuhrmann Well-Known Member

    I think you can extend the route. Since each part of XenForo has their own route with the "buildLink" function, you can extend the route and then do whatever you want for the link using the function buildLink.

    If you want to change links from the "threads" you can extend the route XenForo_Route_Prefix_Threads. Then, overwrite the function buildLink to make a conditional and see if that link which was passed to the functino is the one you want to change.

    So, change the value and return the new one.

    All the {xen:link threads} with provided data will be passed to the buildLink function in the Threads Route.

    I dont have tested this, but it is just an ideia.
     
    tenants likes this.
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    What is the condition? That affects the approach you might take.

    Are we talking about specific threads? Ad links? What is the intention?

    There are many possibilities. A template edit. An addon. The idea that Fuhrmann is talking about is demonstrated in this addon:

    http://xenforo.com/community/threads/change-forums-route-to-view.22998/
     
    tenants likes this.
  4. tenants

    tenants Well-Known Member

    The intention is to redirect threads in a particular forum (the forum Id is an options param). I think fuhrmann is spot on, I'll give it a go ;)
     
    Fuhrmann likes this.

Share This Page