You are here

public static function Bootstrap::preprocess in Express 8

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.

1 call to Bootstrap::preprocess()
bootstrap_preprocess in themes/contrib/bootstrap/bootstrap.theme

File

themes/contrib/bootstrap/src/Bootstrap.php, line 1096
Contains \Drupal\bootstrap\Bootstrap.

Class

Bootstrap
The primary class for the Drupal Bootstrap base theme.

Namespace

Drupal\bootstrap

Code

public static function preprocess(array &$variables, $hook, array $info) {
  static $theme;
  if (!isset($theme)) {
    $theme = self::getTheme();
  }
  static $preprocess_manager;
  if (!isset($preprocess_manager)) {
    $preprocess_manager = new PreprocessManager($theme);
  }

  // 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
      ->getInfo();
    $variables['theme']['dev'] = $theme
      ->isDev();
    $variables['theme']['livereload'] = $theme
      ->livereloadUrl();
    $variables['theme']['name'] = $theme
      ->getName();
    $variables['theme']['path'] = $theme
      ->getPath();
    $variables['theme']['title'] = $theme
      ->getTitle();
    $variables['theme']['settings'] = $theme
      ->settings()
      ->get();
    $variables['theme']['has_glyphicons'] = $theme
      ->hasGlyphicons();
    $variables['theme']['query_string'] = \Drupal::getContainer()
      ->get('state')
      ->get('system.css_js_query_string') ?: '0';
  }

  // 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);
    }
  }
}