function SystemThemeHooks::themeSuggestionsPage

Implements hook_theme_suggestions_HOOK().

Attributes

#[Hook('theme_suggestions_page')]

File

core/modules/system/src/Hook/SystemThemeHooks.php, line 25

Class

SystemThemeHooks
Hook implementations for system.

Namespace

Drupal\system\Hook

Code

public function themeSuggestionsPage(array $variables) : array {
  $path_args = explode('/', trim(\Drupal::service('path.current')->getPath(), '/'));
  $suggestions = theme_get_suggestions($path_args, 'page');
  $supported_http_error_codes = [
    401,
    403,
    404,
  ];
  $exception = \Drupal::requestStack()->getCurrentRequest()->attributes
    ->get('exception');
  if ($exception instanceof HttpExceptionInterface && in_array($exception->getStatusCode(), $supported_http_error_codes, TRUE)) {
    $suggestions[] = 'page__4xx';
    $suggestions[] = 'page__' . $exception->getStatusCode();
  }
  return $suggestions;
}

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