- Issue created by @Anybody
- 🇩🇪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...