function PreprocessHooks::pageTitle

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

Implements hook_preprocess_HOOK() for page_title.

Attributes

#[Hook('preprocess_page_title')]

File

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

Class

PreprocessHooks
Provides preprocess implementations.

Namespace

Drupal\admin\Hook

Code

public function pageTitle(array &$variables) : void {
  if (preg_match('/entity\\.node\\..*/', $this->currentRouteMatch
    ->getRouteName(), $matches)) {
    $node = $this->currentRouteMatch
      ->getParameter('node');
    if ($node instanceof Node) {
      if ($node->isDefaultTranslation() && !in_array($matches[0], [
        'entity.node.content_translation_add',
        'entity.node.delete_form',
      ])) {
        $variables['title'] = $node->getTitle();
      }
      elseif ($matches[0] === 'entity.node.edit_form') {
        $variables['title_attributes']['class'][] = 'page-title--is-translation';
        $args = [
          '@title' => $node->getTitle(),
          '@language' => $node->language()
            ->getName(),
        ];
        $variables['title'] = $this->t('@title <span class="page-title__language">(@language translation)</span>', $args);
      }
    }
  }
}

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