function public static function Bootstrap::preprocess

8.x-3.x Bootstrap.php public static Bootstrap::preprocess(array &$variables, $hook, array $info)

Preprocess theme hook variables.

Parameters

array $variables: The variables array, passed by reference.

string $hook: The name of the theme hook.

array $info: The theme hook info.

Class

Bootstrap
The primary class for the Drupal Bootstrap base theme.

Namespace

Drupal\bootstrap

Source src/Bootstrap.php (line 1374)

public static function preprocess(array &$variables, $hook, array $info) {
  // Do not statically cache this as the active theme may change.
  $theme = static::getTheme();
  $theme_name = $theme->getName();

  // Handle preprocess managers.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['preprocess_managers'] = &drupal_static(__METHOD__ . '__preprocessManagers', []);
    $drupal_static_fast['theme_info'] = &drupal_static(__METHOD__ . '__themeInfo', []);
  }

  /* @var \Drupal\bootstrap\Plugin\PreprocessManager[] $preprocess_managers */
  $preprocess_managers = &$drupal_static_fast['preprocess_managers'];
  if (!isset($preprocess_managers[$theme_name])) {
    $preprocess_managers[$theme_name] = new PreprocessManager($theme);
  }

  // Retrieve the theme info that will be used in the variables.
  $theme_info = &$drupal_static_fast['theme_info'];
  if (!isset($theme_info[$theme_name])) {
    $theme_info[$theme_name] = $theme->getInfo();
    $theme_info[$theme_name]['dev'] = $theme->isDev();
    $theme_info[$theme_name]['livereload'] = $theme->livereloadUrl();
    $theme_info[$theme_name]['name'] = $theme->getName();
    $theme_info[$theme_name]['path'] = $theme->getPath();
    $theme_info[$theme_name]['title'] = $theme->getTitle();
    $theme_info[$theme_name]['settings'] = $theme->settings()->get();
    $theme_info[$theme_name]['has_glyphicons'] = $theme->hasGlyphicons();
    $theme_info[$theme_name]['query_string'] = \Drupal::getContainer()->get('state')->get('system.css_js_query_string') ? : '0';
  }

  // Retrieve the preprocess manager for this theme.
  $preprocess_manager = $preprocess_managers[$theme_name];

  // Add a global "is_admin" variable back to all templates.
  if (!isset($variables['is_admin'])) {
    $variables['is_admin'] = static::isAdmin();
  }

  // Adds a global "is_front" variable back to all templates.
  // @see https://www.drupal.org/node/2829585
  if (!isset($variables['is_front'])) {
    $variables['is_front'] = static::isFront();
    if (static::hasIsFrontCacheContext()) {
      $variables['#cache']['contexts'][] = 'url.path.is_front';
    }
  }

  // Ensure that any default theme hook variables exist. Due to how theme
  // hook suggestion alters work, the variables provided are from the
  // original theme hook, not the suggestion.
  if (isset($info['variables'])) {
    $variables = NestedArray::mergeDeepArray([$info['variables'], $variables], TRUE);
  }

  // Add active theme context.
  // @see https://www.drupal.org/node/2630870
  if (!isset($variables['theme'])) {
    $variables['theme'] = $theme_info[$theme_name];
  }

  // Invoke necessary preprocess plugin.
  if (isset($info['bootstrap preprocess'])) {
    if ($preprocess_manager->hasDefinition($info['bootstrap preprocess'])) {
      $class = $preprocess_manager->createInstance($info['bootstrap preprocess'], ['theme' => $theme]);
      /** @var \Drupal\bootstrap\Plugin\Preprocess\PreprocessInterface $class */
      $class->preprocess($variables, $hook, $info);
    }
  }
}