diff --git a/core/modules/toolbar/src/Element/Toolbar.php b/core/modules/toolbar/src/Element/Toolbar.php index ef3ed54..700f5e2 100644 --- a/core/modules/toolbar/src/Element/Toolbar.php +++ b/core/modules/toolbar/src/Element/Toolbar.php @@ -34,8 +34,9 @@ public function getInfo() { ), // Metadata for the toolbar wrapping element. '#attributes' => array( - // The id cannot be simply "toolbar" or it will clash with the simpletest - // tests listing which produces a checkbox with attribute id="toolbar" + // The id cannot be simply "toolbar" or it will clash with the + // simpletest tests listing which produces a checkbox with attribute + // id="toolbar". 'id' => 'toolbar-administration', 'role' => 'group', 'aria-label' => $this->t('Site administration toolbar'), @@ -69,7 +70,7 @@ public function getInfo() { public static function preRenderToolbar($element) { // Get the configured breakpoints to switch from vertical to horizontal // toolbar presentation. - $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup('toolbar'); + $breakpoints = static::breakpointManager()->getBreakpointsByGroup('toolbar'); if (!empty($breakpoints)) { $media_queries = array(); foreach ($breakpoints as $id => $breakpoint) { @@ -86,10 +87,11 @@ public static function preRenderToolbar($element) { ); } + $module_handler = static::moduleHandler(); // Get toolbar items from all modules that implement hook_toolbar(). - $items = \Drupal::moduleHandler()->invokeAll('toolbar'); + $items = $module_handler->invokeAll('toolbar'); // Allow for altering of hook_toolbar(). - \Drupal::moduleHandler()->alter('toolbar', $items); + $module_handler->alter('toolbar', $items); // Sort the children. uasort($items, array('\Drupal\Component\Utility\SortArray', 'sortByWeightProperty')); @@ -102,4 +104,22 @@ public static function preRenderToolbar($element) { return $element; } + /** + * Wraps the breakpoint manager. + * + * @return \Drupal\breakpoint\BreakpointManagerInterface + */ + protected static function breakpointManager() { + return \Drupal::service('breakpoint.manager'); + } + + /** + * Wraps the module handler. + * + * @return \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected static function moduleHandler() { + return \Drupal::moduleHandler(); + } + } diff --git a/core/modules/toolbar/src/Element/ToolbarItem.php b/core/modules/toolbar/src/Element/ToolbarItem.php index 0591bb2..18ade46 100644 --- a/core/modules/toolbar/src/Element/ToolbarItem.php +++ b/core/modules/toolbar/src/Element/ToolbarItem.php @@ -7,6 +7,7 @@ namespace Drupal\toolbar\Element; +use Drupal\Component\Utility\Html; use Drupal\Core\Render\Element\RenderElement; /** @@ -40,8 +41,8 @@ public function getInfo() { /** * Provides markup for associating a tray trigger with a tray element. * - * A tray is a responsive container that wraps renderable content. Trays present - * content well on small and large screens alike. + * A tray is a responsive container that wraps renderable content. Trays + * present content well on small and large screens alike. * * @param array $element * A renderable array. @@ -51,7 +52,7 @@ public function getInfo() { */ public static function preRenderToolbarItem($element) { // Assign each item a unique ID. - $id = drupal_html_id('toolbar-item'); + $id = Html::getUniqueId('toolbar-item'); // Provide attributes for a toolbar item. $attributes = array(