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
@@ -82,11 +82,13 @@
$page[$label_field] = $page[$label_field]['#page_title'] + $page[$label_field];
}
else {
+ // No title.
$page['#title'] = '';
$skip_render = TRUE;
}
}
+ // Render the title, except in the case where it was set to blank.
if (!isset($skip_render)) {
$page['#title'] = $this->renderer->render($page[$label_field]);
}
reverted:
--- b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TitleFormatter.php
+++ /dev/null
@@ -1,162 +0,0 @@
-getSetting('page') == 'block') {
- $output['#page_title'] = parent::viewElements($items, $langcode);
- }
- else {
- $output['#page_title'] = [];
- }
-
- if (!$this->getSetting('enabled')) {
- return $output;
- }
-
- $attributes = new Attribute();
- $classes = $this->getSetting('classes');
- if (!empty($classes)) {
- $attributes->addClass($classes);
- }
-
- $parent = $items->getParent()->getValue();
- foreach ($items as $item) {
- $text = $item->getValue()['value'];
- if ($this->getSetting('linked')) {
- $text = $this->l($text, $parent->toUrl());
- }
- $output[] = [
- '#type' => 'html_tag',
- '#tag' => $this->getSetting('tag'),
- '#attributes' => $attributes->toArray(),
- '#value' => $text,
- ];
- }
- return $output;
- }
-
- /**
- * {@inheritdoc}
- */
- public function settingsForm(array $form, FormStateInterface $form_state) {
- $heading_options = [
- 'span' => 'span',
- 'div' => 'div',
- ];
- foreach (range(1, 5) as $level) {
- $heading_options['h' . $level] = 'H' . $level;
- }
- $page_options = [
- 'block' => $this->t('Use title block'),
- 'content' => $this->t('Hide block and use format'),
- ];
- $if_enabled = [
- 'visible' => [
- ':input[name="fields[name][settings_edit_form][settings][enabled]"]' => ['checked' => TRUE]
- ]
- ];
-
- $form['enabled'] = [
- '#title' => $this->t('Enabled'),
- '#type' => 'checkbox',
- '#description' => $this->t('Use this setting instead of disabling the title field entirely as it correctly handles the entity shown as a page.'),
- '#default_value' => $this->getSetting('enabled'),
- ];
- $form['page'] = [
- '#title' => $this->t('Page'),
- '#type' => 'select',
- '#description' => $this->t('Behavior when the entity is shown as a page.'),
- '#options' => $page_options,
- '#default_value' => $this->getSetting('page'),
- ];
- $form['tag'] = [
- '#title' => $this->t('Tag'),
- '#type' => 'select',
- '#description' => $this->t('Select the tag which will be wrapped around the title.'),
- '#options' => $heading_options,
- '#default_value' => $this->getSetting('tag'),
- '#states' => $if_enabled,
- ];
- $form['linked'] = [
- '#title' => $this->t('Link to the Content'),
- '#type' => 'checkbox',
- '#description' => $this->t('Wrap the title with a link to the content.'),
- '#default_value' => $this->getSetting('linked'),
- '#states' => $if_enabled,
- ];
- $form['classes'] = [
- '#title' => $this->t('Classes'),
- '#type' => 'textfield',
- '#default_value' => $this->getSetting('classes'),
- '#states' => $if_enabled,
- ];
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function defaultSettings() {
- return [
- 'enabled' => TRUE,
- 'page' => 'block',
- 'tag' => 'h2',
- 'linked' => '1',
- 'classes' => '',
- ];
- }
-
- /**
- * {@inheritdoc}
- */
- public function settingsSummary() {
- $settings = $this->getSettings();
- $page_setting = [
- 'block' => $this->t('On own page use title block'),
- 'content' => $this->t('On own page hide title block and use format'),
- ];
- $summary[] = $page_setting[$settings['page']];
- if ($settings['enabled']) {
- $replacements = ['@tag' => $settings['tag']];
- if ($settings['linked']) {
- $summary[] = $this->t('Display as @tag, linked to content', $replacements);
- }
- else {
- $summary[] = $this->t('Display as @tag', $replacements);
- }
- if (!empty($settings['classes'])) {
- $summary[] = $this->t('Classes: @classes', ['@classes' => $settings['classes']]);
- }
- }
- else {
- array_unshift($summary, $this->t('Disabled'));
- }
-
- return $summary;
- }
-
-}
diff -u b/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc
--- b/core/modules/aggregator/aggregator.theme.inc
+++ b/core/modules/aggregator/aggregator.theme.inc
@@ -46,9 +46,7 @@
$variables['content'][$key] = $variables['elements'][$key];
}
$variables['full'] = $variables['elements']['#view_mode'] == 'full';
- // For the 'title' field, if there are configured display settings then
- // handle as a normal field. If not, then pull the information out into a
- // separate variable.
+ // If the title field is not configurable, make it available separately.
if (!$feed->title->getFieldDefinition()->isDisplayConfigurable('view')) {
$variables['title'] = $feed->label();
}
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,9 +606,8 @@
/** @var \Drupal\node\NodeInterface $node */
$node = $variables['node'];
- // For the fields 'date', 'author_name' and 'title', if there are configured
- // display settings then handle as a normal field. If not, then pull the
- // information out into separate variables.
+ // If the date, author_name 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']);
unset($variables['elements']['created']);
@@ -617,15 +616,19 @@
$variables['author_name'] = \Drupal::service('renderer')->render($variables['elements']['uid']);
unset($variables['elements']['uid']);
}
-
- // By default, the node title template uses a short form inside a span.
- // The output from a generic formatter is likely to contains tags such as
- // headings, so make sure to display the title as a normal field
- // in that case.
- $variables['elements']['title']['#title_as_field'] = $node->title->getFieldDefinition()->isDisplayConfigurable('view');
- if (!$variables['elements']['title']['#title_as_field']) {
+ 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;
}
$variables['url'] = $node->url('canonical', [
@@ -666,7 +669,7 @@
*/
function node_preprocess_field__node__title(&$variables) {
$element = $variables['element'];
- $variables['title_as_field'] = isset($element['#title_as_field']) ? $element['#title_as_field'] : FALSE;
+ $variables['inline_title'] = isset($element['#inline_title']) ? $element['#inline_title'] : FALSE;
}
/**
diff -u b/core/modules/node/templates/field--node--title.html.twig b/core/modules/node/templates/field--node--title.html.twig
--- b/core/modules/node/templates/field--node--title.html.twig
+++ b/core/modules/node/templates/field--node--title.html.twig
@@ -17,18 +17,19 @@
* - label_display: The display settings for the label.
- * - title_as_field: If true, display the title as an ordinary field.
- * If false, display a compact form, typically using inline elements.
+ * - inline_title: If true, display inline elements that will be wrapped in
+ * a header tag by the node template
+ * If false, display the title as an ordinary field.
*
* @see field.html.twig
*
* @ingroup themeable
*/
#}
-{% if title_as_field %}
- {% include "field.html.twig" %}
-{% else %}
+{% if inline_title %}
{%- for item in items -%}
{{ item.content }}
{%- endfor -%}
+{% else %}
+ {% include "field.html.twig" %}
{% endif %}
diff -u b/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
--- b/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -273,9 +273,7 @@
$term = $variables['term'];
$variables['url'] = $term->url();
- // For the 'name' field, if there are configured display settings then handle
- // as a normal field. If not, then pull the information out into a separate
- // variable.
+ // If the name field is not configurable, make it available separately.
// We use name here because that is what appears in the UI.
if (!$term->name->getFieldDefinition()->isDisplayConfigurable('view')) {
$variables['name'] = $variables['elements']['name'];
diff -u b/core/themes/classy/templates/field/field--node--title.html.twig b/core/themes/classy/templates/field/field--node--title.html.twig
--- b/core/themes/classy/templates/field/field--node--title.html.twig
+++ b/core/themes/classy/templates/field/field--node--title.html.twig
@@ -15,15 +15,14 @@
* - field_name: The name of the field.
* - field_type: The type of the field.
* - label_display: The display settings for the label.
- * - title_as_field: If true, display the title as an ordinary field.
- * If false, display a compact form, typically using inline elements.
+ * - inline_title: If true, display inline elements that will be wrapped in
+ * a header tag by the node template
+ * If false, display the title as an ordinary field.
*
* @see field.html.twig
*/
#}
-{% if title_as_field %}
- {% include "field.html.twig" %}
-{% else %}
+{% if inline_title %}
{%
set classes = [
'field',
@@ -39,2 +38,4 @@
+{% else %}
+ {% include "field.html.twig" %}
{% endif %}
diff -u b/core/themes/stable/templates/content/node.html.twig b/core/themes/stable/templates/content/node.html.twig
--- b/core/themes/stable/templates/content/node.html.twig
+++ b/core/themes/stable/templates/content/node.html.twig
@@ -15,7 +15,7 @@
* Calling other methods, such as node.delete(), will result in an exception.
* See \Drupal\node\Entity\Node for a full list of public properties and
* methods for the node object.
- * - label: The title of the node (blank if data should not be shown).
+ * - label: (optional) The title of the node.
* - content: All node items. Use {{ content }} to print them all,
* or print a subset such as {{ content.field_example }}. Use
* {{ content|without('field_example') }} to temporarily suppress the printing
@@ -23,8 +23,8 @@
* - author_picture: The node author user entity, rendered using the "compact"
* view mode.
* - metadata: Metadata for this node.
- * - date: Themed creation date field (blank if data should not be shown).
- * - author_name: Themed author name field (blank if data should not be shown).
+ * - date: (optional) Themed creation date field.
+ * - author_name: (optional) Themed author name field.
* - url: Direct URL of the current node.
* - display_submitted: Whether submission information should be displayed.
* - attributes: HTML attributes for the containing element.
diff -u b/core/themes/stable/templates/field/field--node--title.html.twig b/core/themes/stable/templates/field/field--node--title.html.twig
--- b/core/themes/stable/templates/field/field--node--title.html.twig
+++ b/core/themes/stable/templates/field/field--node--title.html.twig
@@ -17,16 +17,17 @@
* - label_display: The display settings for the label.
- * - title_as_field: If true, display the title as an ordinary field.
- * If false, display a compact form, typically using inline elements.
+ * - inline_title: If true, display inline elements that will be wrapped in
+ * a header tag by the node template
+ * If false, display the title as an ordinary field.
*
* @see field.html.twig
*/
#}
-{% if title_as_field %}
- {% include "field.html.twig" %}
-{% else %}
+{% if inline_title %}
{%- for item in items -%}
{{ item.content }}
{%- endfor -%}
+{% else %}
+ {% include "field.html.twig" %}
{% endif %}