Show extra fields (hook_entity_extra_field_info) only in "Default" display mode by default

Created on 26 August 2025, 3 days ago

Problem/Motivation

When defining new extra fields, they automatically appear in all display modes of all affected entity types.
This stands in contrast to regular fields, which are in "Disabled" region in all display modes despite "Default".

When using extra / pseudo fields in contrib this leads to bad SX / UX, as you have to remove the extra fields from all view modes manually. There's a similar issue for Layout Builder, that's only logically, not technically, related: Prevent auto-adding new fields to LB layouts Needs review

I think in general all field types and layout builder should behave the same and activating the display of fields should be left to the site builder, like for regular fields.

Steps to reproduce

  • Define an extra / pseudo field using hook_entity_extra_field_info or use a contrib module (like Flippy ) that uses extra fields
  • See the extra field being displayed / enabled in all display modes of all affected entities by default

Proposed resolution

Do not add the extra / pseudo field to any other entity display than "Default" by default.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

field system

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Grevil

    Not a big fan of the proposed solution

    Do not add the extra / pseudo field to any other entity display than "Default" by default.

    I'd say the "display type" needs to be defined explicitly, meaning code like this:

          $extra['node'][$type] = [
            'display' => [
              'flippy_pager' => [
                'label' => t('Pager'),
                'description' => t('Flippy module content pager.'),
                'weight' => 5,
                'visible' => TRUE,
              ],
            ],
          ];
    

    would become this:

          $extra['node'][$type] = [
            'display' => [
              'default' => [
                'flippy_pager' => [
                  'label' => t('Pager'),
                  'description' => t('Flippy module content pager.'),
                  'weight' => 5,
                  'visible' => TRUE,
                ],
              ],
            ],
          ];
    

    Furthermore, we should be able to additionally define a "disabled" key. This way we can enable the extra field for all display types but put them in disabled for specific display types.
    Also, I am not quite sure about the backwards compatibility. If we would also allow the old array structure, which simply enables the extra field for all displays as before, we'd had problems with display types being named after an extra field (display type "flippy_pager" and extra field name "flippy_pager").

  • 🇩🇪Germany Anybody Porta Westfalica

    @grevil defining the display type in code wouldn't make much sense, because for example in contrib can't know which entity has which display type. I'd stay with the proposal from the issue summary, but let's see what others say. And of course existing extra / pseudo field display may not change (BC).

  • 🇳🇱Netherlands idebr

    Is this not what the 'visible' key is for?

    visible: (optional) The default visibility of the element. Defaults to TRUE.

    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

  • 🇩🇪Germany Grevil

    @idebr not quite. The "visible" key is responsible for the visibility of the field.

    So if it is set to "FALSE", the field can not be seen through "Manage display" but it is still programmatically accessible.

    @anybody of course contrib can know about the display types. We can simply use "EntityDisplayRepository::getViewModeOptionsByBundle" https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...

Production build 0.71.5 2024