Component subfield labels are duplicated when label display set to above

Created on 15 October 2025, 17 days ago

Problem/Motivation

When a component subfield of a Name element (e.g., Given, Family, Middle, etc.) has its
Label display setting set to title (aka above), the output contains nested <label> elements.

This happens because the Name module pre-renders a themed label and assigns the resulting HTML to #title; Drupal then renders another label for #title, resulting in two labels:

&lt;label for="edit-field-surrogate-0-given" class="form-item__label"&gt;
  &lt;label class="form-item__label"&gt;Given&lt;/label&gt;
&lt;/label&gt;

Steps to reproduce

  1. Add a Name field to a content type (or any entity with a form display).
  2. In the field settings, set a component subfield (e.g., Given) Label display to above.
  3. Open the add/edit form and inspect the markup of that subfield.

Expected: One label per input, rendered by core per #title_display = 'before'.

Actual: Two labels (a label nested inside another label).

Proposed resolution

  • Do not pre-render and inject a themed label into #title for the “title” (above) option.
  • Instead, let Form API/Core render the label:
    • Set $element['#title_display'] = 'before'.
    • Set $element['#required'] = $flag_required_input to control the HTML5 required / aria-required behavior, consistent with other branches.
  • Keep existing behavior for other title_display modes (description/placeholder/none/attribute).

Remaining tasks

  • Implement the change for the title case.
  • Add test coverage to assert there is exactly one label.

User interface changes

  • DOM fix: subfield labels no longer duplicated and nested when “above” is selected.
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇺🇸United States jcandan

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024