Handle multiple forms in one form decorator

Created on 18 June 2025, 2 months ago

Problem/Motivation

Sometimes you want to modify multiple forms. E.g. you have the same form field for multiple node content types. Right now you need to write once form decorator per form.

In hook_form_alter() you can add an if-case and check for a substring to determine multiple forms.

Proposed resolution

A possible solution would be a wildcard. E.g. node_*_edit_form.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Peter Majmesku 🇩🇪Düsseldorf

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

Comments & Activities

  • Issue created by @Peter Majmesku
  • 🇩🇪Germany Hydra

    For those cases it is possible to implement the applies method like this:

      /**
       * {@inheritdoc}
       */
      public function applies(): bool {
        return
          in_array('form_group_type_edit_form_alter', $this->getHooks($this->inner), TRUE)
          || in_array('form_group_type_add_form_alter', $this->getHooks($this->inner), TRUE);
      }
    

    This working example shows how to alter the group edit and group add form at the same time.

Production build 0.71.5 2024