From b733559eb728341ec5092d6decafc9f99be37c93 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 17 Nov 2014 10:51:16 +0000
Subject: [PATCH] Issue #1877482 by bertramakers | benjifisher: Fixed Toolbar
 tabs should have ID attributes based on hook_toolbar() array keys rather than
 sequentially numbering.

---
 core/modules/toolbar/src/Element/Toolbar.php     | 7 +++++++
 core/modules/toolbar/src/Element/ToolbarItem.php | 4 +---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/core/modules/toolbar/src/Element/Toolbar.php b/core/modules/toolbar/src/Element/Toolbar.php
index fac39e2adbca..660ce323f04a 100644
--- a/core/modules/toolbar/src/Element/Toolbar.php
+++ b/core/modules/toolbar/src/Element/Toolbar.php
@@ -7,7 +7,9 @@
 
 namespace Drupal\toolbar\Element;
 
+use Drupal\Component\Utility\Html;
 use Drupal\Core\Render\Element\RenderElement;
+use Drupal\Core\Render\Element;
 
 /**
  * Provides a render element for the default Drupal toolbar.
@@ -97,6 +99,11 @@ public static function preRenderToolbar($element) {
     // Merge in the original toolbar values.
     $element = array_merge($element, $items);
 
+    // Assign each item a unique ID, based on its key.
+    foreach (Element::children($element) as $key) {
+      $element[$key]['#id'] = Html::getId('toolbar-item-' . $key);
+    }
+
     // Render the children.
     $element['#children'] = drupal_render_children($element);
 
diff --git a/core/modules/toolbar/src/Element/ToolbarItem.php b/core/modules/toolbar/src/Element/ToolbarItem.php
index e596687df114..929dac410d63 100644
--- a/core/modules/toolbar/src/Element/ToolbarItem.php
+++ b/core/modules/toolbar/src/Element/ToolbarItem.php
@@ -7,7 +7,6 @@
 
 namespace Drupal\toolbar\Element;
 
-use Drupal\Component\Utility\Html;
 use Drupal\Core\Render\Element\RenderElement;
 use Drupal\Core\Url;
 
@@ -50,8 +49,7 @@ public function getInfo() {
    *   A renderable array.
    */
   public static function preRenderToolbarItem($element) {
-    // Assign each item a unique ID.
-    $id = Html::getUniqueId('toolbar-item');
+    $id = $element['#id'];
 
     // Provide attributes for a toolbar item.
     $attributes = array(
-- 
GitLab