function ThemePreprocess::preprocessPage

Prepares variables for the page template.

Default template: page.html.twig.

See the page.html.twig template for the list of variables.

File

core/lib/Drupal/Core/Theme/ThemePreprocess.php, line 330

Class

ThemePreprocess
Preprocess for common/core theme templates.

Namespace

Drupal\Core\Theme

Code

public function preprocessPage(array &$variables) : void {
  $language_interface = $this->languageManager
    ->getCurrentLanguage();
  foreach ($this->themeManager
    ->getActiveTheme()
    ->getRegions() as $region) {
    if (!isset($variables['page'][$region])) {
      $variables['page'][$region] = [];
    }
  }
  $variables['base_path'] = base_path();
  $variables['front_page'] = Url::fromRoute('<front>')->toString();
  $variables['language'] = $language_interface;
  // An exception might be thrown.
  try {
    $variables['is_front'] = $this->pathMatcher
      ->isFrontPage();
  } catch (\Exception) {
    // If the database is not yet available, set default values for these
    // variables.
    $variables['is_front'] = FALSE;
    $variables['db_is_active'] = FALSE;
  }
  if (($node = $this->routeMatch
    ->getParameter('node')) || ($node = $this->routeMatch
    ->getParameter('node_preview'))) {
    $variables['node'] = $node;
  }
}

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