Skip to content

Commit

Permalink
Check language too
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Oct 9, 2017
1 parent 30749ae commit 3a5506e
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions libraries/src/Component/Router/Rules/MenuRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,29 @@ public function preprocess(&$query)
{
$active = $this->router->menu->getActive();

if (isset($query['Itemid']))
/**
* If the active item id is not the same as the supplied item id or we have a supplied item id and no active
* menu item then we just use the supplied menu item and continue
*/
if (isset($query['Itemid']) && ($active === null || $query['Itemid'] != $active->id))
{
/**
* If the active item id is not the same as the supplied item id or we have a supplied item id and no active
* menu item then we just use the supplied menu item and continue
*/
if ($active === null || $query['Itemid'] != $active->id)
{
return;
}
return;
}

// Get query language
$language = isset($query['lang']) ? $query['lang'] : '*';

if ((isset($query['option']) === false || $query['option'] === $active->query['option'])
if ($active !== null)
{
// Test if query lang match active language
$matchLanguage = $language === '*'
|| in_array($active->language, array('*', $language))
|| \JLanguageMultilang::isEnabled() === false;

// Check if the active menu item matches the requested language, option, view and layout
if (isset($query['Itemid'])
&& $matchLanguage
&& (isset($query['option']) === false || $query['option'] === $active->query['option'])
&& (isset($query['view']) === false
|| isset($active->query['view']) && $query['view'] === $active->query['view'])
&& (isset($query['layout']) === false
Expand All @@ -86,7 +97,10 @@ public function preprocess(&$query)
{
$key = $views[$active->query['view']]->key;

if ($key === false || isset($query[$key]) === false || current(explode(':', $query[$key], 2)) == $active->query[$key])
// Check if the active menu item matches the requested key
if ($key === false
|| isset($query[$key]) === false
|| current(explode(':', $query[$key], 2)) == $active->query[$key])
{
// If the same view has two different menu items and one of them is active then use the active one
return;
Expand All @@ -95,18 +109,9 @@ public function preprocess(&$query)
}
}

if (isset($query['lang']))
{
$language = $query['lang'];

if (!isset($this->lookup[$language]))
{
$this->buildLookup($language);
}
}
else
if ($language !== '*' && isset($this->lookup[$language]) === false)
{
$language = '*';
$this->buildLookup($language);
}

$needles = $this->router->getPath($query);
Expand Down Expand Up @@ -149,8 +154,7 @@ public function preprocess(&$query)
}

// Check if the active menuitem matches the requested language
if ($active && $active->component === 'com_' . $this->router->getName()
&& ($language === '*' || in_array($active->language, array('*', $language)) || !\JLanguageMultilang::isEnabled()))
if ($active && $active->component === 'com_' . $this->router->getName() && $matchLanguage)
{
$query['Itemid'] = $active->id;
return;
Expand Down

0 comments on commit 3a5506e

Please sign in to comment.