summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/toolbar
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/toolbar')
-rw-r--r--core/modules/toolbar/src/Hook/ToolbarThemeHooks.php23
-rw-r--r--core/modules/toolbar/tests/modules/toolbar_test/src/Hook/ToolbarTestThemeHooks.php30
-rw-r--r--core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module19
-rw-r--r--core/modules/toolbar/toolbar.module11
4 files changed, 53 insertions, 30 deletions
diff --git a/core/modules/toolbar/src/Hook/ToolbarThemeHooks.php b/core/modules/toolbar/src/Hook/ToolbarThemeHooks.php
new file mode 100644
index 00000000000..fb08f0ffde6
--- /dev/null
+++ b/core/modules/toolbar/src/Hook/ToolbarThemeHooks.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Drupal\toolbar\Hook;
+
+use Drupal\Core\Hook\Attribute\Hook;
+
+/**
+ * Hook implementations for toolbar.
+ */
+class ToolbarThemeHooks {
+
+ /**
+ * Implements hook_preprocess_HOOK() for HTML document templates.
+ */
+ #[Hook('preprocess_html')]
+ public function preprocessHtml(&$variables): void {
+ if (!\Drupal::currentUser()->hasPermission('access toolbar')) {
+ return;
+ }
+ $variables['attributes']['class'][] = 'toolbar-loading';
+ }
+
+}
diff --git a/core/modules/toolbar/tests/modules/toolbar_test/src/Hook/ToolbarTestThemeHooks.php b/core/modules/toolbar/tests/modules/toolbar_test/src/Hook/ToolbarTestThemeHooks.php
new file mode 100644
index 00000000000..e1d40c8219a
--- /dev/null
+++ b/core/modules/toolbar/tests/modules/toolbar_test/src/Hook/ToolbarTestThemeHooks.php
@@ -0,0 +1,30 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Drupal\toolbar_test\Hook;
+
+use Drupal\Core\Hook\Attribute\Hook;
+
+/**
+ * Hook implementations for toolbar_test.
+ */
+class ToolbarTestThemeHooks {
+
+ /**
+ * Implements hook_preprocess_HOOK().
+ */
+ #[Hook('preprocess_menu')]
+ public function preprocessMenu(&$variables): void {
+ // All the standard hook_theme variables should be populated when the
+ // Toolbar module is rendering a menu.
+ foreach ([
+ 'menu_name',
+ 'items',
+ 'attributes',
+ ] as $variable) {
+ $variables[$variable];
+ }
+ }
+
+}
diff --git a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module b/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module
deleted file mode 100644
index 8980eb4a6ef..00000000000
--- a/core/modules/toolbar/tests/modules/toolbar_test/toolbar_test.module
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-/**
- * @file
- * A dummy module to test API interaction with the Toolbar module.
- */
-
-declare(strict_types=1);
-
-/**
- * Implements hook_preprocess_HOOK().
- */
-function toolbar_test_preprocess_menu(&$variables): void {
- // All the standard hook_theme variables should be populated when the
- // Toolbar module is rendering a menu.
- foreach (['menu_name', 'items', 'attributes'] as $variable) {
- $variables[$variable];
- }
-}
diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module
index 51986310901..4bfcd89e187 100644
--- a/core/modules/toolbar/toolbar.module
+++ b/core/modules/toolbar/toolbar.module
@@ -118,17 +118,6 @@ function toolbar_menu_navigation_links(array $tree) {
}
/**
- * Implements hook_preprocess_HOOK() for HTML document templates.
- */
-function toolbar_preprocess_html(&$variables): void {
- if (!\Drupal::currentUser()->hasPermission('access toolbar')) {
- return;
- }
-
- $variables['attributes']['class'][] = 'toolbar-loading';
-}
-
-/**
* Returns the rendered subtree of each top-level toolbar link.
*
* @return array