Change record status: 
Project: 
Introduced in branch: 
8.7.x
Introduced in version: 
8.7.0
Description: 

The following node base fields are not configurable via the field UI by default:

  • node.title
  • node.uid
  • node.created

Furthermore developers who wished enable configurable display of these fields have until now been obstructed by special preprocessing.

There is now a way to disable this special preprocessing, so that it becomes possible for developers to make the base field display configurable via the field UI. The contrib module Manage Display provides this.

Before

Developers could set one of these fields to be configurable, for example by:

function mymodule_entity_base_field_info_alter(&$base_field_definitions, EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'node') {
    $base_field_definitions['title']->setDisplayConfigurable('view', TRUE);
  }
}

If a developer did this, the field would appear in the "Manage Display" field UI. However any changes made there would have no effect as the title would be rendered in a fixed position at the top of the node template. This happened because of special preprocessing in template_preprocess_node to take the title out of the variable {{ content }} and move it into {{ label }}.

After

Developers can bypass this special base field preprocessing using the following hook:

function mymodule_entity_type_build(array &$entity_types) {
  $entity_types['node']->set('enable_base_field_custom_preprocess_skipping', TRUE);
}

With both this hook and above one in place, the base fields will correctly respond to changes in the field UI settings.

Template changes

The special variables representing the preprocessed base fields are now optional in the node template. The core templates Stable, Classy, Bartik and Umami have been modified with conditional logic before accessing:

  • label
  • author_name
  • date

Contrib theme developers should make the corresponding changes to their templates so that they work correctly if configurable display of base fields is enabled. However the changes are fully back-compatible, so that existing sites that do not enable configurable display of base fields do not need to change templates.

Future plans

Work is continuing to bring configurable display of base fields directly into core, without requiring contrib modules.

The long-term intention (perhaps in Drupal 9) is to remove the special preprocessing entirely and enable configurable display of base fields by default. It would still be possible for a developer to go back to having the title hard-coded in the template using a hook plus the following approach in the template.

{{ content.title }}
{{ content|without('title') }}
Impacts: 
Site builders, administrators, editors
Themers