Skip to content
Snippets Groups Projects

Issue #3218877: Labels do not have correct 'for' attribute if 'id' set in #attributes

Closed Issue #3218877: Labels do not have correct 'for' attribute if 'id' set in #attributes
1 unresolved thread
Closed Ben Mullins requested to merge issue/drupal-3218877:3218877-labels-do-not into 9.3.x
1 unresolved thread
Files
4
@@ -977,6 +977,17 @@ public function doBuildForm($form_id, &$element, FormStateInterface &$form_state
$element['#array_parents'] = [];
}
if (!empty($element['#attributes']['id']) && is_array($element['#attributes']['id'])) {
@trigger_error('Providing IDs as an array is deprecated in drupal:9.3.0 and is removed in drupal:10.0.0. Only use string values for ID.', E_USER_DEPRECATED);
$element['#attributes']['id'] = reset($element['#attributes']['id']);
}
// If an ID is set in #attributes, copy to $element['#id'] as there is
// rendering logic that only checks there for explicitly set IDs.
if (!isset($element['#id']) && !empty($element['#attributes']['id'])) {
$element['#id'] = $element['#attributes']['id'];
}
if (!isset($element['#id'])) {
$unprocessed_id = 'edit-' . implode('-', $element['#parents']);
$element['#id'] = Html::getUniqueId($unprocessed_id);
Loading