diff --git a/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php index 581054e..1ef63b8 100644 --- a/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php @@ -58,18 +58,25 @@ public static function create(ContainerInterface $container) { /** * Pre-render callback to build the page title. + * + * @param array $page + * A render array. + * + * @return array + * The changed render array. */ - public function buildTitle($page) { + public function buildTitle(array $page) { $entity_type = $page['#entity_type']; $entity = $page['#' . $entity_type]; - $view_mode = $page['#view_mode']; // 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'); - $page['#title'] = $this->renderer->render($page[$label_field]); + if (isset($page[$label_field]) && $title = $this->renderer->render($page[$label_field])) { + $page['#title'] = $title; + } } return $page; } diff --git a/core/modules/node/src/Controller/NodePreviewController.php b/core/modules/node/src/Controller/NodePreviewController.php index 9fb0e7b..030a0d4 100644 --- a/core/modules/node/src/Controller/NodePreviewController.php +++ b/core/modules/node/src/Controller/NodePreviewController.php @@ -25,8 +25,7 @@ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $lan $build['#attached']['library'][] = 'node/drupal.node.preview'; - $build['#title'] = $build['nodes']['#title']; - unset($build['nodes']['#title']); + $build['#pre_render'][] = [$this, 'buildPreviewTitle']; // Don't render cache previews. unset($build['nodes']['#cache']); @@ -55,6 +54,23 @@ public function view(EntityInterface $node_preview, $view_mode_id = 'full', $lan } /** + * A pre render callback that pulls out the title from the node pre render. + * + * @param array $build + * A render array. + * + * @return array + * The changed render array. + */ + public function buildPreviewTitle(array $build) { + $build['nodes'] = call_user_func($build['nodes']['#pre_render'][0], $build['nodes']); + $build['nodes'] = call_user_func($build['nodes']['#pre_render'][1], $build['nodes']); + + $build['#title'] = $build['nodes']['#title']; + return $build; + } + + /** * The _title_callback for the page that renders a single node in preview. * * @param \Drupal\Core\Entity\EntityInterface $node_preview