function ToolbarThemeHooks::libraryInfoAlter

Same name and namespace in other branches
  1. main core/modules/toolbar/src/Hook/ToolbarThemeHooks.php \Drupal\toolbar\Hook\ToolbarThemeHooks::libraryInfoAlter()

Implements hook_library_info_alter().

Attributes

#[Hook('library_info_alter')]

File

core/modules/toolbar/src/Hook/ToolbarThemeHooks.php, line 146

Class

ToolbarThemeHooks
Hook implementations for toolbar.

Namespace

Drupal\toolbar\Hook

Code

public function libraryInfoAlter(&$libraries, $extension) : void {
  // If Claro is the admin theme but not the active theme, grant Claro the
  // ability to override the toolbar library with its own assets.
  if ($extension === 'toolbar' && $this->isClaroAdminAndNotActive()) {
    // If the active theme is not Claro, but Claro is the admin theme, this
    // alters the toolbar library config so Claro's toolbar stylesheets are
    // used.
    $claro_info = $this->themeHandler
      ->listInfo()['claro']->info;
    $path_prefix = '/core/themes/claro/';
    $claro_toolbar_overrides = $claro_info['libraries-override']['toolbar/toolbar'];
    foreach ($claro_toolbar_overrides['css'] as $concern => $overrides) {
      foreach ($claro_toolbar_overrides['css'][$concern] as $key => $value) {
        $config = $libraries['toolbar']['css'][$concern][$key];
        $libraries['toolbar']['css'][$concern][$path_prefix . $value] = $config;
        unset($libraries['toolbar']['css'][$concern][$key]);
      }
    }
    $claro_toolbar_menu_overrides = $claro_info['libraries-override']['toolbar/toolbar.menu'];
    foreach ($claro_toolbar_menu_overrides['css'] as $concern => $overrides) {
      foreach ($claro_toolbar_menu_overrides['css'][$concern] as $key => $value) {
        $config = $libraries['toolbar.menu']['css'][$concern][$key];
        $libraries['toolbar.menu']['css'][$concern][$path_prefix . $value] = $config;
        unset($libraries['toolbar.menu']['css'][$concern][$key]);
      }
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.