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

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?
 
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.
 
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 ;)
 
Top Bottom