Skip to content

Commit

Permalink
Fix routing for Joomla 4
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Jul 12, 2022
1 parent b5f6c39 commit 855cd57
Showing 1 changed file with 16 additions and 42 deletions.
58 changes: 16 additions & 42 deletions src/site/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,57 +378,29 @@ public function preprocess($query)
$task = $query['task'] ?? null;
$id = $query['id'] ?? null;
$itemId = $query['Itemid'] ?? null;
$parts = $query;

$parts = $query;
if ($itemId) {
$menu = $this->menu->getItem($itemId);
if ($menu) {
$menuView = $menu->query['view'] ?? null;
$menuTask = $menu->query['task'] ?? null;

if ($view && $view != $menuView) {
switch ($view) {
case 'item':
if ($id && ($viewMenu = $this->helper->getMenuItemForFile($id))) {
$itemId = $viewMenu->id;

} else {
$categoryId = $this->helper->getCategoryIdFromFileId($id);

$categoryMenu = $this->helper->getMenuItemForListOfFiles($categoryId)
?: $this->helper->getMenuItemForListOfFiles(0);
if ($categoryMenu) {
$itemId = $categoryMenu->id;

} else {
$itemId = null;
unset($parts['Itemid']);
}
}
break;
}
if ($view) {
switch ($view) {
case 'item':
if ($id && ($viewMenu = $this->helper->getMenuItemForFile($id))) {
$viewItemid = $viewMenu->id;

} elseif ($task && $task != $menuTask && $id) {
if ($itemMenu = $this->helper->getMenuItemForFile($id)) {
$itemId = $itemMenu->id;
} else {
$categoryId = $this->helper->getCategoryIdFromFileId($id);

} elseif ($categoryId = $this->helper->getCategoryIdFromFileId($id)) {
$categoryMenu = $this->helper->getMenuItemForListOfFiles($categoryId)
?: $this->helper->getMenuItemForListOfFiles(0);

if ($categoryMenu) {
$itemId = $categoryMenu->id;

} else {
$itemId = null;
unset($parts['Itemid']);
$viewItemid = $categoryMenu->id;
}
}
}
}

} elseif ($view) {
switch ($view) {
if ($itemId == ($viewItemid ?? 0)) {
$itemId = null;
}
break;

case 'downloads':
$listMenu = $this->helper->getMenuItemForListOfFiles($id)
?: $this->helper->getMenuItemForListOfFiles(0);
Expand All @@ -452,6 +424,8 @@ public function preprocess($query)

if ($itemId) {
$parts['Itemid'] = $itemId;
} elseif (isset($parts['Itemid'])) {
unset($parts['Itemid']);
}

return $parts;
Expand Down

0 comments on commit 855cd57

Please sign in to comment.