From d2a88b3a18a3b7dc05f5654b198a3c4bdf10de3c Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Wed, 1 Dec 2021 08:25:01 +0100 Subject: [PATCH] chg: [Component:Navigation] Breadcrumbs get loaded before rendering to have access to view var So that it can have access to view variables --- src/Controller/AppController.php | 6 +++++- src/Controller/Component/Navigation/base.php | 4 +++- src/Controller/Component/NavigationComponent.php | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 3771796..53d1b24 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -128,7 +128,6 @@ class AppController extends Controller } $this->ACL->checkAccess(); - $this->set('breadcrumb', $this->Navigation->getBreadcrumb()); $this->set('ajax', $this->request->is('ajax')); $this->request->getParam('prefix'); $this->set('baseurl', Configure::read('App.fullBaseUrl')); @@ -143,6 +142,11 @@ class AppController extends Controller } } + public function beforeRender(EventInterface $event) + { + $this->set('breadcrumb', $this->Navigation->getBreadcrumb()); + } + private function authApiUser(): void { if (!empty($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER['HTTP_AUTHORIZATION'])) { diff --git a/src/Controller/Component/Navigation/base.php b/src/Controller/Component/Navigation/base.php index 84dde96..3900e69 100644 --- a/src/Controller/Component/Navigation/base.php +++ b/src/Controller/Component/Navigation/base.php @@ -5,11 +5,13 @@ class BaseNavigation { protected $bcf; protected $request; + protected $viewVars; - public function __construct($bcf, $request) + public function __construct($bcf, $request, $viewVars) { $this->bcf = $bcf; $this->request = $request; + $this->viewVars = $viewVars; } public function addRoutes() {} diff --git a/src/Controller/Component/NavigationComponent.php b/src/Controller/Component/NavigationComponent.php index 92c44b5..0f3569f 100644 --- a/src/Controller/Component/NavigationComponent.php +++ b/src/Controller/Component/NavigationComponent.php @@ -42,7 +42,7 @@ class NavigationComponent extends Component $this->request = $config['request']; } - public function beforeFilter($event) + public function beforeRender($event) { $this->fullBreadcrumb = $this->genBreadcrumb(); $this->breadcrumb = $this->getBreadcrumb(); @@ -140,7 +140,8 @@ class NavigationComponent extends Component $navigationClassname = str_replace('.php', '', $navigationFile); require_once(APP . 'Controller' . DS . 'Component' . DS . 'Navigation' . DS . $navigationFile); $reflection = new \ReflectionClass("BreadcrumbNavigation\\{$navigationClassname}Navigation"); - $navigationClasses[$navigationClassname] = $reflection->newInstance($bcf, $request); + $viewVars = $this->_registry->getController()->viewBuilder()->getVars(); + $navigationClasses[$navigationClassname] = $reflection->newInstance($bcf, $request, $viewVars); } return $navigationClasses; } @@ -249,6 +250,7 @@ class BreadcrumbFactory $routeConfig = $this->addIfNotEmpty($routeConfig, $config, 'icon'); $routeConfig = $this->addIfNotEmpty($routeConfig, $config, 'label'); $routeConfig = $this->addIfNotEmpty($routeConfig, $config, 'textGetter'); + $routeConfig = $this->addIfNotEmpty($routeConfig, $config, 'badge'); return $routeConfig; }