Allow themes to alter widget forms

Created on 2 June 2017, over 7 years ago
Updated 30 January 2023, almost 2 years ago

Problem/Motivation

\Drupal\Core\Field\WidgetBase::formSingleElement only allows modules to alter the resulting form. This makes it impossible for themes to consistently make changes to the widget form.

The only workaround would be to recursively loop over every element in a form looking for the characteristics of a widget form, which may not even be possible.

An example of why this would be a common scenario would be the datelist widget - it add's a fieldset around the elements. It would be entirely reasonable for a theme to want to use the composite fieldset to make date fields look consistent with other form elements. This is not possible at the moment.

Not sure if this should be marked as a bug, as I expect it's a non-intentional regression from D&.

Proposed resolution

Pass the widget form alter onto themes as well as modules.

API changes

Themes would be able to implement hook_field_widget_form_alter() and hook_field_widget_WIDGET_TYPE_form_alter().

Feature request
Status

Needs work

Version

10.1

Component
Field 

Last updated about 12 hours ago

Created by

🇬🇧United Kingdom andrewbelcher

Live updates comments and jobs are added and updated live.
  • Contributed project blocker

    It denotes an issue that prevents porting of a contributed project to the stable version of Drupal due to missing APIs, regressions, and so on.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Production build 0.71.5 2024