I'm developing a Joomla! 3.9.x component and have written a custom com_myusers component. I want to avoid that people login/reset/remind using the standard com_users component and I thought the best way to do that was to write a system plugin that detects the option and view, and in case it's the com_users component it would redirect to the corresponding com_myusers view. So I wonder if there is a reliable function or way to get the internal url of a SEF url or any other way to solve this. Thanks for sharing your ideas!
1 Answer
The Joomla router will set up the "option", "view" etc input parameters once it's parsed the SEF URL. So you just have to overwrite those values using the input set
method (https://api.joomla.org/cms-3/classes/Joomla.CMS.Input.Input.html#method_set). Then your component/view will be executed instead.
So define a group="system" plugin which listens for the OnAfterRoute event (which is what is triggered once the router has done its job). Something like this:
public function onAfterRoute()
{
$app = JFactory::getApplication();
if ($app->isSite())
{
$input = $app->input;
$option = $input->get('option');
$view = $input->get('view');
if ($option == "com_users")
{
$input->set('option', 'com_myusers');
$input->set('view', 'myview');
}
}
}
(only with more rigorous checking that $option and $view are set, and equal to the appropriate values).
-
That way I am able to get what I want, and the redirect happens under the hood (I can see my views are displayed instead of the Joomla! ones) but the url in the browser's address field doesn't change of course. Would it be wrong to use $app->redirect(JRoute::_('index.php?option=com_myusers&view=' . $view)) instead?– RicoCommented Feb 21, 2020 at 14:49
-
1I can't see any reason why redirect wouldn't work as well, so probably that would be a better solution, as users then would see the right URL, as you say. Commented Feb 21, 2020 at 17:41