Skip to content

Commit

Permalink
Add a better check for query params with alias like id:alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Oct 8, 2017
1 parent 94fae0c commit 3347526
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
36 changes: 24 additions & 12 deletions libraries/src/Component/Router/Rules/MenuRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,33 @@ public function preprocess(&$query)
{
$active = $this->router->menu->getActive();

/**
* 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 (isset($query['Itemid']))
{
return;
}
/**
* 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;
}

if ($active !== null)
{
$activeQuery = $active->query;
$activeQuery['Itemid'] = $active->id;
$query2 = array();

foreach ($active->query as $k => $v)
{
if (isset($query[$k])) {
// Remove every alias from query2 because item query does not contain aliases
list($query2[$k]) = explode(':', $query[$k], 2);
}
else
{
// Add missing keys in query that exists in item->query
$query2[$k] = $v;
}
}

if ($activeQuery === $query)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ public function testPreprocessActive()
$this->object->preprocess($query);
$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');
$this->object->preprocess($query);
$this->assertEquals($expect, $query);

$this->restoreFactoryState();
}

Expand Down

0 comments on commit 3347526

Please sign in to comment.