- Issue created by @mrshowerman
- 🇩🇪Germany tobiasb Berlin
A field label is used for input (form) and output (view), but did not want to change the label for input, therefore we did this via code for the output.
- 🇩🇪Germany mrshowerman Munich
Got it.
But when a site chooses to use the same label for form and output, they have to write their own hook to revert the upstream logic.Here's what we did:
/** * Implements hook_ENTITY_TYPE_view_alter(). */ function mymodule_node_view_alter(array &$build, NodeInterface $entity): void { if ($entity->bundle() === 'date' && $build['#view_mode'] === 'full') { foreach (['field_location', 'field_event_description'] as $field_name) { $label = $entity->getFieldDefinition($field_name)->getLabel(); $build[$field_name]['#title'] = $label; } } }
I wonder if there is a better way to achieve different labels in form and view displays that is easier to disable, without having to write custom hooks.
- 🇩🇪Germany hexabinaer Berlin, Germany
I would assume the easier way is to enable interface translation to English /admin/config/regional/language/edit/en and use User Interface Translation for custom labels.
At least as long as Drupal core does not support a differentiation between form labels and output labels.