You are here

function html_title_preprocess_page_title in HTML Title 8

Implements hook_preprocess_page_title().

File

./html_title.module, line 35
HTML Title module to enable limited HTML tags in title.

Code

function html_title_preprocess_page_title(&$variables) {
  if ($nid = \Drupal::routeMatch()
    ->getRawParameter('node')) {
    $node = \Drupal::entityTypeManager()
      ->getStorage('node')
      ->load($nid);
    $node = \Drupal::service('entity.repository')
      ->getTranslationFromContext($node);
    $title = \Drupal::service('html_title.filter')
      ->decodeToMarkup($node
      ->label());
    if (\Drupal::routeMatch()
      ->getRouteName() === 'entity.node.edit_form') {
      $title = t('<em>Edit @type</em> @title', [
        '@type' => node_get_type_label($node),
        '@title' => \Drupal::service('html_title.filter')
          ->decodeToMarkup($node
          ->label()),
      ]);
    }
    $variables['title'] = $title;
  }
}