Problem/Motivation
I run into an issue where Field Group Table module did not recognise the new label because it is using the canonical field render-array property:
$element['#title']
while Entity Form Field Label only modifies a theme variable:
$variables['label']
That means its override is invisible to any render-array processor that runs before Twig. Field Group Table is one example, but other modules could have the same problem.
Proposed resolution
Add another function to the module to enforce change also via hook_entity_view_alter():
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_view_alter().
*/
function entity_form_field_label_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display): void {
foreach ($display->getComponents() as $field_name => $component) {
if (!isset($build[$field_name]) || !is_array($build[$field_name])) {
continue;
}
$plugin = $display->getRenderer($field_name);
if (!$plugin instanceof ThirdPartySettingsInterface) {
continue;
}
$label_settings = $plugin->getThirdPartySettings(
'entity_form_field_label'
);
if (empty($label_settings['rewrite_label'])) {
continue;
}
$build[$field_name]['#title'] = $label_settings['new_label'];
}
}
Remaining tasks
Review and commit.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
jannakha commentedplease provide merge request as it will speed up testing and review process