You are here

public function EntityViewController::buildTitle in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Controller/EntityViewController.php \Drupal\Core\Entity\Controller\EntityViewController::buildTitle()
  2. 10 core/lib/Drupal/Core/Entity/Controller/EntityViewController.php \Drupal\Core\Entity\Controller\EntityViewController::buildTitle()

Pre-render callback to build the page title.

Parameters

array $page: A page render array.

Return value

array The changed page render array.

File

core/lib/Drupal/Core/Entity/Controller/EntityViewController.php, line 71

Class

EntityViewController
Defines a generic controller to render a single entity.

Namespace

Drupal\Core\Entity\Controller

Code

public function buildTitle(array $page) {
  $entity_type = $page['#entity_type'];
  $entity = $page['#' . $entity_type];

  // If the entity's label is rendered using a field formatter, set the
  // rendered title field formatter as the page title instead of the default
  // plain text title. This allows attributes set on the field to propagate
  // correctly (e.g. RDFa, in-place editing).
  if ($entity instanceof FieldableEntityInterface) {
    $label_field = $entity
      ->getEntityType()
      ->getKey('label');
    if (isset($page[$label_field])) {
      $page['#title'] = $this->renderer
        ->render($page[$label_field]);
    }
  }
  return $page;
}