From efb6cd38d86cfa859de848191b67ff0d0eef06e7 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 15 Jan 2020 12:12:04 +0100 Subject: [PATCH] fix #3342 @0.75 --- .../Http/Controllers/CubistPageController.php | 7 ++++--- src/app/Magic/Menu/Item.php | 4 ++-- src/app/Magic/Menu/Menu.php | 2 +- src/app/Magic/Menu/PageItem.php | 2 +- src/app/Template/Navigation.php | 1 + src/app/Template/Redirection.php | 3 +++ src/app/Template/TemplateAbstract.php | 16 +++++++++++++++- 7 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/app/Http/Controllers/CubistPageController.php b/src/app/Http/Controllers/CubistPageController.php index 6c79881..ccf32ad 100644 --- a/src/app/Http/Controllers/CubistPageController.php +++ b/src/app/Http/Controllers/CubistPageController.php @@ -12,11 +12,11 @@ use Illuminate\Support\Str; class CubistPageController extends CubistFrontController { - public function index(Request $request, $slug = 'home') + public function index(Request $request, $id) { $class = CMSPage::getPageClass(); /** @var CMSPage $page */ - $page = Menu::getNavigation()->findOneBy('slug', $slug)->getEntity(); + $page = Menu::getNavigation()->findOneById($id)->getEntity(); if (!$page) { $this->_404(); @@ -49,7 +49,8 @@ class CubistPageController extends CubistFrontController $path = 'home'; } $nav = Menu::getNavigation(); - $item = $nav->findItemWithURL($path); + $item = $nav->findItemWithURL($path,true); + if (null === $item) { $redirectItem = $nav->findOneWithAlias($path); if (null !== $redirectItem) { diff --git a/src/app/Magic/Menu/Item.php b/src/app/Magic/Menu/Item.php index 543d556..44f82fc 100644 --- a/src/app/Magic/Menu/Item.php +++ b/src/app/Magic/Menu/Item.php @@ -272,14 +272,14 @@ class Item return null; } - public function findItemWithURL($href) + public function findItemWithURL($href, $restrictToNavigable = true) { foreach ($this->findAllBy('href', $href) as $item) { if (!($item instanceof PageItem)) { return $item; } /** @var $item PageItem */ - if (stripos($item->getTemplate(), 'redirection') !== false) { + if ($restrictToNavigable && !$item->isNavigable()) { continue; } return $item; diff --git a/src/app/Magic/Menu/Menu.php b/src/app/Magic/Menu/Menu.php index 9ef7045..031f0f4 100644 --- a/src/app/Magic/Menu/Menu.php +++ b/src/app/Magic/Menu/Menu.php @@ -93,7 +93,7 @@ class Menu extends BaseMenu /** @var PageItem $template */ if (null !== $page->getPage()) { $template = $page->getPage()->getUsedTemplate(); - if ($template instanceof Redirection || $template instanceof Navigation) { + if (!$template->isNavigable()) { continue; } } diff --git a/src/app/Magic/Menu/PageItem.php b/src/app/Magic/Menu/PageItem.php index 91d0876..6daa438 100644 --- a/src/app/Magic/Menu/PageItem.php +++ b/src/app/Magic/Menu/PageItem.php @@ -188,7 +188,7 @@ class PageItem extends Item public function getController(): array { if (!$this->_controller) { - return ['controller' => 'PageController', 'action' => 'index', 'params' => ['slug' => $this->getSlug()]]; + return ['controller' => 'PageController', 'action' => 'index', 'params' => ['id' => $this->getId()]]; } return parent::getController(); } diff --git a/src/app/Template/Navigation.php b/src/app/Template/Navigation.php index 40527ed..22d285e 100644 --- a/src/app/Template/Navigation.php +++ b/src/app/Template/Navigation.php @@ -7,6 +7,7 @@ namespace Cubist\Backpack\app\Template; class Navigation extends TemplateAbstract { protected $_virtual = true; + protected $_navigable = false; public function init() { diff --git a/src/app/Template/Redirection.php b/src/app/Template/Redirection.php index 1e9dc48..b979630 100644 --- a/src/app/Template/Redirection.php +++ b/src/app/Template/Redirection.php @@ -6,6 +6,9 @@ namespace Cubist\Backpack\app\Template; class Redirection extends TemplateAbstract { + + protected $_navigable = false; + public function init() { parent::init(); diff --git a/src/app/Template/TemplateAbstract.php b/src/app/Template/TemplateAbstract.php index 6660173..21dc7d0 100644 --- a/src/app/Template/TemplateAbstract.php +++ b/src/app/Template/TemplateAbstract.php @@ -16,8 +16,14 @@ class TemplateAbstract protected $defaultFieldAttributes = []; protected $_fields = []; - + /** + * @var bool + */ protected $_virtual = false; + /** + * @var bool + */ + protected $_navigable = true; public function __construct() { @@ -144,6 +150,14 @@ class TemplateAbstract return $this->_virtual; } + /** + * @return bool + */ + public function isNavigable() + { + return $this->_navigable; + } + /** * @param $data array Current page data for the view -- 2.39.5