Joomla 3.8 override component router.

111 views
Skip to first unread message

stephan...@gmail.com

unread,
Mar 14, 2018, 7:26:59 AM3/14/18
to Joomla! CMS Development
With the modern component router it's possible to remove ID.

I need to override some component router.php only to change the
getArticleId
getArticleSegment

What is the best way to override article and other router

thanks
Stéphane

stephan...@gmail.com

unread,
Mar 15, 2018, 6:50:59 AM3/15/18
to Joomla! CMS Development
Thanks to Hannes Papenberg for this response

require_once JPATH_ROOT . '/components/com_content/router.php';
class plgSystemWhatever extends JPlugin
{
public function onAfterInitialise()
{
$app = JFactory::getApplication();
if (!$app->isSite()) return;
$router = $app->getRouter();
$crouter = new MyCustomRouter($app, $app->getMenu());
$router->setComponentRouter('com_content', $crouter);
}
}

class MyCustomRouter extends ContentRouter
{
public function __construct($app = null, $menu = null)
{
parent::__construct($app, $menu);
//need to override router name
$this->name = 'content';

}
}

Reply all
Reply to author
Forward
0 new messages