diff -u b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php --- b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php +++ b/core/lib/Drupal/Core/Entity/Controller/EntityViewController.php @@ -70,28 +70,31 @@ if ($entity instanceof FieldableEntityInterface) { $label_field = $entity->getEntityType()->getKey('label'); if (isset($page[$label_field])) { + // The #page_title property allows the label field render array to + // specify how the page title should be rendered. It should be empty + // or a render array. This property is only required if the page + // title is different from the standard field output. + $showTitle = TRUE; if (isset($page[$label_field]['#page_title'])) { - // The desired markup for use in the page title may be different from - // that to use when displaying the title field as content. - // Allow the title field formatter to provide separate markup for the - // first case using the #page_title array property, which should be - // set to a render array of child elements. - if ($page[$label_field]['#page_title']) { - // Combine the two arrays, giving preference to #page_title, but - // also preserving the #properties from the base field array. - $page[$label_field] = $page[$label_field]['#page_title'] + $page[$label_field]; + if (empty($page[$label_field]['#page_title'])) { + // The page title should be suppressed. + $showTitle = FALSE; } else { - // No title. - $page['#title'] = ''; - $skip_render = TRUE; + // The label field formatter has provided an alternate render + // array for this circumstance. Fill out any missing properties in + // it by merging in the usual label render array. + $page[$label_field] = $page[$label_field]['#page_title'] + $page[$label_field]; } } - // Render the title, except in the case where it was set to blank. - if (!isset($skip_render)) { + // Render the page title if required. + if ($showTitle) { $page['#title'] = $this->renderer->render($page[$label_field]); } + else { + $page['#title'] = ''; + } } } return $page; diff -u b/core/modules/node/node.module b/core/modules/node/node.module --- b/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -606,7 +606,7 @@ /** @var \Drupal\node\NodeInterface $node */ $node = $variables['node']; - // If the date, author_name and title fields are not configurable, make them + // If the created, uid and title fields are not configurable, make them // available separately. if (!$node->created->getFieldDefinition()->isDisplayConfigurable('view')) { $variables['date'] = \Drupal::service('renderer')->render($variables['elements']['created']); @@ -616,19 +616,15 @@ $variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']); unset($variables['elements']['uid']); } - if ($node->title->getFieldDefinition()->isDisplayConfigurable('view')) { + if (!$node->title->getFieldDefinition()->isDisplayConfigurable('view')) { $variables['label'] = $variables['elements']['title']; unset($variables['elements']['title']); - // The field template (field--node--title.html.twig) must generate inline - // elements that the node template wraps in a header tag. - // @todo It is unfortunate that the field template has to handle this - // special case, but for back-compatibility reasons it is not possible - // to change the behavior until D9. - $variables['elements']['title']['#inline_title'] = TRUE; - } - else { - // The title field must be displayed as a normal field. - $variables['elements']['title']['#inline_title'] = FALSE; + + // The node template will apply its own markup around the label. + // Therefore the node title template needs to be instructed to generate + // only inline markup in this situation. + // @todo Simplify in D9 + $variables['label']['#inline_title'] = TRUE; } $variables['url'] = $node->url('canonical', [