function PreprocessHooks::toolbar

Same name and namespace in other branches
  1. 11.x core/themes/admin/src/Hook/PreprocessHooks.php \Drupal\admin\Hook\PreprocessHooks::toolbar()

Implements toolbar preprocess.

This is also called by system_preprocess_toolbar() in instances where Admin is the administration theme but not the active theme.

Attributes

#[Hook('preprocess_toolbar')]

See also

system_preprocess_toolbar()

File

core/themes/admin/src/Hook/PreprocessHooks.php, line 1223

Class

PreprocessHooks
Provides preprocess implementations.

Namespace

Drupal\admin\Hook

Code

public function toolbar(array &$variables) : void {
  $variables['attributes']['data-drupal-gin-processed-toolbar'] = TRUE;
  // The controller resolver does not support Closures at this time. For now,
  // we use a wrapper function to load the service with dependencies.
  // @see https://www.drupal.org/project/drupal/issues/3060638
  $variables['user_picture'] = [
    '#lazy_builder' => [
      static::class . '::lazyToolbarUserPicture',
      [],
    ],
    '#create_placeholder' => TRUE,
  ];
  // Check if Navigation module is active.
  if ($this->moduleHandler
    ->moduleExists('navigation')) {
    // Attach the new drupal navigation styles.
    $variables['#attached']['library'][] = 'admin/navigation';
    return;
  }
  // Toolbar library.
  $variables['#attached']['library'][] = 'admin/toolbar';
}

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