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
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
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
Joomla 3.8.12
Labels |
Added:
?
|
Labels |
Added:
J3 Issue
|
But this is like "hardcoded" It should be possible to link to another site in another language in my opinion.
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.
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...
I suggest to add a lang
parameter to $item->flink = 'index.php?Itemid=' . $item->params->get('aliasoptions');
in mod_menu helper.php.
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;
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;
}
}
Why not use something like ...getMenu()->getItem((int) $item->params->get('aliasoptions'));
aliasoptions
only contains the itemid
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?
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:)
your code saves a query.
Will do PR, knowing that it will not work when the site does not use the core module.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-10-11 09:26:16 |
Closed_By | ⇒ | infograf768 |
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:
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
and it will work fine.