J3 Issue ?
avatar B3nito
B3nito
6 Oct 2018

Steps to reproduce the issue

On a mulilanguage site create a menuitem in language A.
In language B setup a menu item alias to the item of the language A

Expected result

When you Click on menu item alias in Language B you are redirected to Menuitem in Language A
languagedomain.com/B/ -> languagedomain.com/A/mydesireditem

Actual result

You are redirected to a new Menuitem of language B with content of A, and everything surrounding is wrong.
languagedomain.com/B/ -> languagedomain.com/B/mydesireditem, wrong modules

System information (as much as possible)

Joomla 3.8.12

Additional comments

avatar B3nito B3nito - open - 6 Oct 2018
avatar joomla-cms-bot joomla-cms-bot - change - 6 Oct 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 Oct 2018
avatar infograf768
infograf768 - comment - 6 Oct 2018

In a multilingual site, one should never use an alias menu item to a menu item tagged to another language. As the language is not set correctly, one will get into various issues, the one concerning modules being an obvious one.
If you need to create a menu item in language A which will display a menu item in language B, use the URL menu item.

First copy the link of the menu item in language B:
screen shot 2018-10-06 at 11 08 56

here it is index.php?option=com_content&view=category&layout=blog&id=9

Then create a URL menu item in language A, enter the link you just copied and add the lang
Example for French (French is language B)
index.php?option=com_content&view=category&layout=blog&id=9&lang=fr

It will look like
screen shot 2018-10-06 at 10 54 27

and it will work fine.

avatar brianteeman brianteeman - change - 8 Oct 2018
Labels Added: J3 Issue
avatar brianteeman brianteeman - labeled - 8 Oct 2018
avatar B3nito
B3nito - comment - 10 Oct 2018

But this is like "hardcoded" It should be possible to link to another site in another language in my opinion.

avatar infograf768
infograf768 - comment - 11 Oct 2018

I may have a solution to make alias menu item multilingual aware.
Obviously this will not link to another site but the same site when the menu item targeted is tagged to another language.

avatar infograf768
infograf768 - comment - 11 Oct 2018

hmm. That would only be for Protostar as my modifications are only for now in the menu module.
have to find a more general way. Not obvious...

avatar csthomas
csthomas - comment - 11 Oct 2018

I suggest to add a lang parameter to $item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions'); in mod_menu helper.php.

avatar infograf768
infograf768 - comment - 11 Oct 2018

I have done that and PR is ready, but it would work ONLY when using the core menu module.

diff --git a/modules/mod_menu/helper.php b/modules/mod_menu/helper.php
index dbc9254..0d69d4e 100644
--- a/modules/mod_menu/helper.php
+++ b/modules/mod_menu/helper.php
@@ -115,5 +115,28 @@
 
 						case 'alias':
-							$item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');
+							// Query the language of the target menu item
+							if (JLanguageMultilang::isEnabled())
+							{
+								$db = \JFactory::getDbo();
+								$query = $db->getQuery(true)
+									->select($db->quoteName('language'))
+									->from($db->quoteName('#__menu'))
+									->where($db->quoteName('id') . ' = ' . (int) $item->params->get('aliasoptions'));
+
+								$db->setQuery($query);
+								$language = $db->loadResult();
+							}
+
+							// Use language code if not set to ALL
+							if ($language && JLanguageMultilang::isEnabled() && $language !== '*')
+							{
+								$lang = '&lang=' . $language;
+							}
+							else
+							{
+								$lang = '';
+							}
+
+							$item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions') . $lang;
 							break;
avatar HLeithner
HLeithner - comment - 11 Oct 2018

I would suggest streamlined variant

$item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');

// Query the language of the target menu item
if (JLanguage::MultilangisEnabled())
{
  $db    = \JFactory::getDbo();
  $query = $db->getQuery(true)
              ->select($db->quoteName('language'))
              ->from($db->quoteName('#__menu'))
              ->where($db->quoteName('id') . ' = ' . (int) $item->params->get('aliasoptions'));

  $db->setQuery($query);
  $language = $db->loadResult();
  // Use language code if not set to ALL
  if ($language !== '*')
  {
    $item->flink .= '&lang=' . $language;
  }
}
avatar csthomas
csthomas - comment - 11 Oct 2018

Why not use something like ...getMenu()->getItem((int) $item->params->get('aliasoptions'));

avatar infograf768
infograf768 - comment - 11 Oct 2018

aliasoptions only contains the itemid

avatar infograf768
infograf768 - comment - 11 Oct 2018

but the issue is, as I see it, that it would only work for the core menu module.
Is it worth doing it in that case?

avatar csthomas
csthomas - comment - 11 Oct 2018

I do not see a problem with

$newItem = JFactory::getApplication()->getMenu()->getItem((int) $item->params->get('aliasoptions'));
$language = $newItem->language;

Is it worth doing it in that case?

IMO yes, but I have not have any multilingual website yet:)

avatar infograf768
infograf768 - comment - 11 Oct 2018

your code saves a query.
Will do PR, knowing that it will not work when the site does not use the core module.

avatar infograf768
infograf768 - comment - 11 Oct 2018

See #22579

closing as we have a patch.

avatar infograf768 infograf768 - change - 11 Oct 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-10-11 09:26:16
Closed_By infograf768
avatar infograf768 infograf768 - close - 11 Oct 2018

Add a Comment

Login with GitHub to post a comment