XF 2.1 router_public_setup to override buildLink/route?

cmpe

Active member
My addon extends threads controller as well as xf_threads table and has its own route.

My goal is to "override" links to threads in all templates, for example:
Code:
link('threads', $threads)

So that conditionally, it can use the correct route and return the overridden link if the thread is the extended type.

I know I can use assertCanonicalUrl in the controller but wondering if I can take it a step further.

I think what I'll need to do is create a new event listener for router_public_setup and I had an idea of how to implement this at 3am last night but now I forgot lol.

Is what I want to do even doable with router_public_setup or is there a better way to implement this?
 
Oh wait, I think the idea I had yesterday was to add a custom link building callback to the existing threads route but then I didn't like the idea of modifying one of the default routes for XF (what addon would 'own' this route in this case?).
 
What I ended up with was putting the 2 and 2 from my two posts above together which is so obvious but couldn't remember from my 3am coding session.

Created a code event listener for router_public_setup and override the router->route to my custom link building function which is I guess the extendable way of adding the custom link building callback. And of course from the custom callback I can check for the condition and modify the prefix if it matches the condition.

Assuming this is the best way to do what I want but feel free to chime in if there is a better way.
 
Top Bottom