Skip to content

Commit

Permalink
[Modern Routing] make a simpler loop in StandardRules::build (#19271)
Browse files Browse the repository at this point in the history
* Simpler loop in build method of StandardRules

* Now use last_id only

* Remove useless code

* Remove support for new router configuration
  • Loading branch information
csthomas authored and Michael Babker committed Feb 13, 2018
1 parent 34d33a1 commit 74cc659
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions libraries/src/Component/Router/Rules/StandardRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public function build(&$query, &$segments)
// Get the menu item belonging to the Itemid that has been found
$item = $this->router->menu->getItem($query['Itemid']);

if ($item === null || $item->component !== 'com_' . $this->router->getName())
if ($item === null
|| $item->component !== 'com_' . $this->router->getName()
|| !isset($item->query['view']))
{
return;
}
Expand All @@ -202,7 +204,7 @@ public function build(&$query, &$segments)
$views = $this->router->getViews();

// Return directly when the URL of the Itemid is identical with the URL to build
if (isset($item->query['view']) && $item->query['view'] === $query['view'])
if ($item->query['view'] === $query['view'])
{
$view = $views[$query['view']];

Expand Down Expand Up @@ -241,65 +243,66 @@ public function build(&$query, &$segments)
}

// Get the path from the view of the current URL and parse it to the menu item
$path = array_reverse($this->router->getPath($query), true);
$found = false;
$found2 = false;
$path = array_reverse($this->router->getPath($query), true);
$found = false;

for ($i = 0, $j = count($path); $i < $j; $i++)
foreach ($path as $element => $ids)
{
reset($path);
$view = key($path);
$view = $views[$element];

if ($found)
if ($found === false && $item->query['view'] === $element)
{
$ids = array_shift($path);
if ($view->nestable)
{
$found = true;
}
elseif ($view->children)
{
$found = true;

continue;
}
}

if ($found === false)
{
// Jump to the next view
continue;
}

if ($views[$view]->nestable)
if ($ids)
{
if ($view->nestable)
{
$found2 = false;

foreach (array_reverse($ids, true) as $id => $segment)
{
if ($found2)
{
$segments[] = str_replace(':', '-', $segment);
}
elseif ((int) $item->query[$views[$view]->key] == (int) $id)
elseif ((int) $item->query[$view->key] === (int) $id)
{
$found2 = true;
}
}
}
elseif (is_bool($ids))
elseif ($ids === true)
{
$segments[] = $views[$view]->name;
$segments[] = $element;
}
else
{
$segments[] = str_replace(':', '-', array_shift($ids));
$segments[] = str_replace(':', '-', current($ids));
}
}
elseif ($item->query['view'] !== $view)
{
array_shift($path);
}
else
{
if (!$views[$view]->nestable)
{
array_shift($path);
}
else
{
$i--;
$found2 = false;
}

if (count($views[$view]->children))
{
$found = true;
}
if ($view->parent_key)
{
// Remove parent key from query
unset($query[$view->parent_key]);
}

unset($query[$views[$view]->parent_key]);
}

if ($found)
Expand Down

0 comments on commit 74cc659

Please sign in to comment.