From 4e66cd7c20b249bee6cc0d327776e6732613aa03 Mon Sep 17 00:00:00 2001 From: Sascha Eggenberger <hello@saschaeggenberger.com> Date: Sat, 15 Jul 2023 02:18:58 +0200 Subject: [PATCH] Add active trail paths and fix code styles --- README.md | 3 +- gin_toolbar.install | 5 +- gin_toolbar.module | 4 +- src/Menu/GinToolbarActiveTrail.php | 85 +++++++++++++++++++++++++++--- src/Render/Element/GinToolbar.php | 4 +- 5 files changed, 87 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ce29685..a0d7809 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ Helper module to bring the Gin toolbar into the Frontend of your site. Requires the [Gin Admin Theme](https://drupal.org/project/gin). -This module is needed due to some technical limitations of Drupal (Admin) themes. +This module is needed due to some technical limitations of +Drupal (Admin) themes. - For a full description of the module, visit the [project page](https://www.drupal.org/project/gin_toolbar). - Use the [Issue queue](https://www.drupal.org/project/issues/gin_toolbar) to submit bug reports and feature suggestions, or track changes. diff --git a/gin_toolbar.install b/gin_toolbar.install index edd854c..bca478a 100644 --- a/gin_toolbar.install +++ b/gin_toolbar.install @@ -30,8 +30,9 @@ function gin_toolbar_requirements($phase) { // Check if Drupal should be installed and gin in is in the install profile. if (InstallerKernel::installationAttempted() && isset($install_state['profile_info']['themes']) - && in_array('gin', $install_state['profile_info']['themes'], TRUE)) { - return $requirements; + && in_array('gin', $install_state['profile_info']['themes'], TRUE) + ) { + return $requirements; } // Gin is not installed and it's not supposed to be installed. diff --git a/gin_toolbar.module b/gin_toolbar.module index c68670e..02bfce3 100644 --- a/gin_toolbar.module +++ b/gin_toolbar.module @@ -8,9 +8,9 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\gin_toolbar\Render\Element\GinToolbar; -use Drupal\gin\GinUserPicture; use Drupal\gin\GinSettings; +use Drupal\gin\GinUserPicture; +use Drupal\gin_toolbar\Render\Element\GinToolbar; /** * Implements hook_preprocess_HOOK() for html. diff --git a/src/Menu/GinToolbarActiveTrail.php b/src/Menu/GinToolbarActiveTrail.php index c59450e..7305734 100644 --- a/src/Menu/GinToolbarActiveTrail.php +++ b/src/Menu/GinToolbarActiveTrail.php @@ -5,9 +5,7 @@ namespace Drupal\gin_toolbar\Menu; use Drupal\Core\Menu\MenuActiveTrail; /** - * Class GinToolbarActiveTrail. - * - * @package Drupal\gin_toolbar\Menu + * Handles the active trail. */ class GinToolbarActiveTrail extends MenuActiveTrail { @@ -20,6 +18,20 @@ class GinToolbarActiveTrail extends MenuActiveTrail { $route_name = $this->routeMatch->getRouteName(); $route_params = $this->routeMatch->getRawParameters()->all(); + // Content. + if (in_array($route_name, [ + 'system.admin_content', + 'node.add_page', + 'entity.node.canonical', + 'entity.node.edit_form', + ])) { + $link = $this->getLinkByRoutes($menu_name, [ + [$route_name, $route_params], + ['system.admin_content', []], + ]); + } + + // Create Content. if ($route_name === 'node.add') { $link = $this->getLinkByRoutes($menu_name, [ [$route_name, $route_params], @@ -28,17 +40,76 @@ class GinToolbarActiveTrail extends MenuActiveTrail { ]); } - if ($route_name === 'node.add_page') { + // Media. + if (in_array($route_name, [ + 'view.media_library.page', + 'entity.media.collection', + 'entity.media.add_page', + 'entity.media.add_form', + ])) { $link = $this->getLinkByRoutes($menu_name, [ [$route_name, $route_params], - ['system.admin_content', []], + ['entity.media.collection', []], ]); } - if (in_array($route_name, ['entity.node.canonical', 'entity.node.edit_form'])) { + // Create Media. + if ($route_name === 'entity.media.add_form') { $link = $this->getLinkByRoutes($menu_name, [ [$route_name, $route_params], - ['system.admin_content', []], + ['entity.media.add_page', []], + ['entity.media.collection', []], + ]); + } + + // Files. + if ($route_name === 'view.files.page_1') { + $link = $this->getLinkByRoutes($menu_name, [ + [$route_name, $route_params], + ['view.files.page_1 ', []], + ]); + } + + // Blocks. + if ($route_name === 'entity.block_content.collection') { + $link = $this->getLinkByRoutes($menu_name, [ + [$route_name, $route_params], + ['entity.block_content.collection', []], + ]); + } + + // User. + if (in_array($route_name, [ + 'entity.user.collection', + 'user.role.settings', + ])) { + $link = $this->getLinkByRoutes($menu_name, [ + [$route_name, $route_params], + ['entity.user.collection', []], + ]); + } + + // Reports. + if (in_array($route_name, [ + 'dblog.overview', + 'dblog.access_denied', + 'dblog.page_not_found', + 'dblog.search', + ])) { + $link = $this->getLinkByRoutes($menu_name, [ + [$route_name, $route_params], + ['system.admin_reports', []], + ]); + } + + // Configuration. + if (in_array($route_name, [ + 'system.admin_config', + 'devel.admin_settings', + ])) { + $link = $this->getLinkByRoutes($menu_name, [ + [$route_name, $route_params], + ['system.admin_config', []], ]); } diff --git a/src/Render/Element/GinToolbar.php b/src/Render/Element/GinToolbar.php index 0366c6b..f513dec 100644 --- a/src/Render/Element/GinToolbar.php +++ b/src/Render/Element/GinToolbar.php @@ -6,9 +6,9 @@ use Drupal\Core\Menu\MenuTreeParameters; use Drupal\Core\Security\TrustedCallbackInterface; /** - * Class GinToolbar. + * Adds active trail to trail. * - * @package Drupal\gin_toolbar\Render\Element + * * @package Drupal\gin_toolbar\Render\Element. */ class GinToolbar implements TrustedCallbackInterface { -- GitLab