XF 2.0 Change the route of a thread?

Jaxel

Well-known member
For my article system, I'm trying to get article threads to be in the articles/ route, instead of threads/.

I know I could just cut and paste the entire contents of XF:Thread->actionIndex() to my action... but I was hoping not to do this because it wouldn't degrade gracefully in the event that XF:Thread->actionIndex() receives changes during XF2 upgrades.

So I tried this:
Code:
    public function actionArticle(ParameterBag $params)
    {
        return $this->rerouteController('XF:Thread', 'index', $params);
    }

But then I released that this doesn't work either, because XF:Thread->actionIndex() asserts canonical URLs.

So is there a good way to do what I am trying to do, without just copying the entire action?
 
Add a class extension for XF\Pub\Controller\Thread and override public function assertCanonicalUrl($linkUrl), inspecting the URL to see if is an article URL and if so, return;

Just make sure you run parent::assertCanonicalUrl($linkUrl) if the passed URL is NOT an article URL.


Fillip
 
You could also override the route building to make sure that the canonical url for article threads is the articles route.

You would add a filter to the Router using the router_public_setup code event, I believe.

Liam
 
Liam's solution is best, mine's more hacky and less resilient to upgrades so if you were to use his method instead that'd be preferable.


Fillip
 
I'm not seeing anything in \XF\Container $container, \XF\Mvc\Router &$router which references the actual parameters of the thread. I assume I needed to fetch the $thread_id, check if its an article, then temporarily add a $routeFilterIn with the replacement...

But there is no parameterBag in this function.
 
Back
Top Bottom