Skip to content

Commit

Permalink
Back to simpler way
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Oct 9, 2017
1 parent 6e1e3d9 commit 8740d71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
49 changes: 22 additions & 27 deletions libraries/src/Component/Router/Rules/MenuRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,43 +75,37 @@ public function preprocess(&$query)
// Get query language
$language = isset($query['lang']) ? $query['lang'] : '*';

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

if ($active !== null)
// Check if the active menu item matches the requested query
if ($active !== null && isset($query['Itemid']))
{
// 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
|| isset($active->query['layout']) && $query['layout'] === $active->query['layout']))
{
$views = $this->router->getViews();
// Check if active->query and supplied query are the same
$match = true;

if (isset($views[$active->query['view']]))
foreach ($active->query as $k => $v)
{
if (isset($query[$k]) && $v !== $query[$k])
{
$key = $views[$active->query['view']]->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])
// Compare again without alias
if (is_string($v) && $v == current(explode(':', $query[$k], 2)))
{
// If the same view has two different menu items and one of them is active then use the active one
return;
continue;
}

$match = false;
break;
}
}

if ($match)
{
// Just use the supplied menu item
return;
}
}

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

// Check if the active menuitem matches the requested language
if ($active && $active->component === 'com_' . $this->router->getName() && $matchLanguage)
if ($active && $active->component === 'com_' . $this->router->getName()
&& ($language === '*' || in_array($active->language, array('*', $language)) || !\JLanguageMultilang::isEnabled()))
{
$query['Itemid'] = $active->id;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ public function testPreprocessActive()
'option' => 'com_content',
'view' => 'article',
'id' => '1:some-alias',
// Additional parameter that is not a key but exists for example in category view
'filter_tag' => array(''),
'Itemid' => '53');
$this->object->preprocess($query);
$this->assertEquals($expect, $query);
Expand Down

0 comments on commit 8740d71

Please sign in to comment.