Add the ability to hide the top-level field label

Created on 5 December 2022, about 2 years ago
Updated 8 December 2023, about 1 year ago

Problem/Motivation

Currently the name module allows you to customize the display of the individual field component labels within the widget, but not of the top level field label itself. This can lead to odd/unintuitive display issues. For example, if the individual components are set to show their labels above the fields, then the widget is displayed like this:

In this case, the the top level field name ("Name") is redundant, and it would be nice if this could be hidden.

Currently this can be done by adding a hook for field_widget_name_default_form_alter and setting $element['#title_display'] = 'invisible';, but I end up doing this in every project so thought it might be good to have a setting for this within the module as this seems to be a common occurrence.

Proposed resolution

Add an extra setting within the name field configuration called field_title_display which allows the options of before, visually_hidden and none.

This would be overridable at the field level.

(This setting should be ignored for multi-cardinality fields as WidgetBase explicitly configures the field label for multi-cardinality fields).

The attached patch makes these changes. Please let me know if there's anything in the patch you'd like changed or amended (or feel free to close if you think this is out of scope!)

User interface changes

Adds an extra dropdown setting to the name field configuration form.

Data model changes

Schema change to store the new setting.

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom JeremySkinner

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

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