Refactor Label Help to use hook_field_widget_WIDGET_TYPE_form_alter

Created on 23 December 2024, about 1 month ago

Problem/Motivation

Currently we're using a Form API #process callback with a long, confusing function and Array-of-doom logic to match certain edge cases dealing with different Drupal field types. This makes the module hard to read, hard to contribute, and hard to review and test.

Proposed resolution

Rearchitect and refactor the module to utilize a series of hook_field_widget_WIDGET_TYPE_form_alter() functions, one for each field widget type (i.e. field formatter) we intend to support. Widget types—not field types—are the things that have the most intimate knowledge of each field's internal render array oddities and structure.

This would break the one single long function into separate smaller functions. Within each widget type, there might still be a need for some case logic, but the vast majority of the current if/else control structures would be simply obviated by implementing adequate [WIDGET_TYPE] functions.

Remaining tasks

Work on a quick and dirty proof of concept, based around a few widget types.
Once the approach is shown to work, prove out the rest of the core widget types.
Revisit contrib module integrations, such as Paragraphs #2731637: Add Label Help support for Paragraphs module fields .

User interface changes

None.

API changes

None.

Data model changes

None.

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

🇪🇨Ecuador jwilson3

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

Comments & Activities

Production build 0.71.5 2024