Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modern Routing] make a simpler loop in StandardRules::build #19271

Merged
merged 4 commits into from
Feb 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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