#923 Posted in ‘Route 66’

Latest post by Lefteris Kavadas on Friday, 02 September 2022 11:57 EEST

Pavel
Hi,

I use Route 66 (free version) on https://uraloved.ru to get nice article URLs containing article alias only (e. g. https://uraloved.ru/reka-chusovaya instead of long URL with a chain of all parent categories). It's important that menu item was detected and modules were assigned correctly.

The extension worked fine on Joomla 3.10.x and on Joomla 4.1.5. However, today, just after update to Joomla 4.2.1, it has broken. Now, the menu item is detected incorrectly. You can see that the active menu item on the example page above is "Главная" (it's slightly highlighted in the menu row), while the correct menu item should be "Места". Also, the module assignment is broken, as well as the overall page layout. It's expected that the page will look like this: https://uraloved.ru/about, with a large left margin (in fact, it's an empty column in the template) and with a few modules in the right column. However, only one column in shown, and apart from this, the "Новые статьи" heading is added to the top of the page, and this is also wrong.

To sum it up, it seems that menu item is detected incorrectly, and this incorrect detection results in several problems with module assignment and layout.

Joomla 4.2.1, Route 66 1.9.7

Will be glad if the bug (if any) is fixed soon or if you can give me any tips on how to deal with this issue.

With regards,

Pavel

Lefteris Kavadas
Hi Pavel,

Just tested under Joomla 4.2.1 and modules assignment works fine.
Is there any chance that there are articles with duplicate alias in your site?
Can you please ensure that not both of those menu items are linking to the same article category?

Regards

Pavel
In fact, there have been articles with duplicated aliases (I found 3 such articles), but I've changed the aliases so now all aliases are unique, and nothing has changed.
"Главная" menu item is a list of featured articles, and "Места" is a link to a category, so these menu items do not point at the same category.
Now I'm trying to look at the plugin's code to see what happens and where things may go wrong. Maybe this is a site-specific issue which results from a combination of settings. Can you please tell me which files, classes and methods are used to detect menu item and assign modules?

Pavel
Looks like that I've managed to fix this problem.

After debugging with logging $Itemid value on different steps of application execution, I've found out that route66 system plugin itself detects and sets menu item id correctly. It happens in plugins/system/route66/lib/router.php.

public function postParse($router, $uri)
{
    ...
    if (isset($this->vars['Itemid']))
    {
        $this->menu->setActive($this->vars['Itemid']); // itemid is 120, which is correct
    }
}


However, when I log $Itemid in libraries/src/Application/SiteApplication.php, in getTemplate method, I obtain different value.

public function getTemplate($params = false)
{
    ...		
    // Get the id of the active menu item
    $menu = $this->getMenu();
    $item = $menu->getActive(); // here item id is 101, which corresponds to the main page
...
}


So, setting active menu item in route66 system plugin seems to have no effect. It looks like that active menu item is set on two instances of menu object. I've fixed the problem by a slight change of the code of setMenu method in plugin file.

Existing code
private function setMenu()
{
    $application = JFactory::getApplication();
    $site = CMSApplication::getInstance('site');
    $this->menu = $site->getMenu();
...
}


My hotfix
private function setMenu()
{
    $application = JFactory::getApplication();
    //$site = CMSApplication::getInstance('site');
    $this->menu = $application->getMenu();
...
}


Now everything works. Unfortunately, it's a hack of plugin's code.

At this point, I can't understand why on my site menu getter created two different objects instead of returning the same object for all calls.

Lefteris Kavadas
Hi Pavel,

You have provided great feedback for our extension. Thank you.
Since you are familiar with coding here are a few things you can try:

1. Make sure that the plugin named "System - Route 66" is ordered last.
2. If the above does not solve the issue try to edit file /plugins/system/route66/lib/router.php and add the following code in line 392:
			$application = JFactory::getApplication();
			if ($application->isClient('site'))
			{
				$menu = $application->getMenu();
				$menu->setActive($this->vars['Itemid']);
			}


The new version of the postParse function should look like this:
	public function postParse($router, $uri)
	{
		$router->setVars($this->vars);

		if (count($this->vars))
		{
			$uri->setPath('');
			$uri->setQuery(array_merge($uri->getQuery(true), $this->vars));
		}

		if (isset($this->vars['Itemid']))
		{
			$this->menu->setActive($this->vars['Itemid']);
			$application = JFactory::getApplication();
			if ($application->isClient('site'))
			{
				$menu = $application->getMenu();
				$menu->setActive($this->vars['Itemid']);
			}
		}
	}


Please let me know if any of those suggestions solve the issue.

Regards

Pavel
1. "System - Route 66" plugin has always been ordered last, so it's unlikely that problem had appeared due to the order of plugins.
2. Solution you have advised works. However, it looks like I'll have to edit this file each time after plugin update :(

Lefteris Kavadas
Hi Pavel,

No, you will not have to edit this file after each update. This fix will get included in our plugin as long as it resolves the issue.
Thank you very much for the great feedback you have provided!

Regards

Note: An active subscription is required in order to get support for our paid extensions. For our free extensions, if you don't have an account, register and then submit your support request.  In case you just want to ask a question, you can also use the contact form .

Firecoders
Are you using our extensions? Please post a review at the Joomla extensions directory!
Post a review