Skip to content

Commit

Permalink
Use router->view->key to compare menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Oct 8, 2017
1 parent 3347526 commit 30749ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
31 changes: 15 additions & 16 deletions libraries/src/Component/Router/Rules/MenuRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,24 @@ public function preprocess(&$query)
return;
}

$query2 = array();

foreach ($active->query as $k => $v)
if ((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']))
{
if (isset($query[$k])) {
// Remove every alias from query2 because item query does not contain aliases
list($query2[$k]) = explode(':', $query[$k], 2);
}
else
$views = $this->router->getViews();

if (isset($views[$active->query['view']]))
{
// Add missing keys in query that exists in item->query
$query2[$k] = $v;
}
}
$key = $views[$active->query['view']]->key;

if ($active->query === $query2)
{
// If the same view has two different menu items and one of them is active then use the active one
return;
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ public function testPreprocessActive()
$this->assertEquals($expect, $query);

// Test if the active Itemid is used although an article has other Itemid with id=52
$expect = $query = array('option' => 'com_content', 'view' => 'article', 'id' => '1:some-alias', 'Itemid' => '53');
$expect = $query = array(
'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 30749ae

Please sign in to comment.