Issue #3580222: Use Element::children() in elementFormAfterBuild()

Issue #3580222

Problem

elementFormAfterBuild() iterates over $form["elements"] with a raw foreach, which assumes every value is an array. When a form element contains a TranslatableMarkup object at the top level of $form["elements"], PHP throws:

Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array

Fix

Replace the raw foreach ($form["elements"] as $element_id => $element) with Element::children(), which filters out non-array values and property keys (those starting with #).

This is the standard Drupal approach for iterating over render array children, and is already used in the same class by the findFormElements() method.

Changes

  • src/Hook/FormHooks.php: Use Element::children() in the elementFormAfterBuild() loop (1 line changed)

Merge request reports

Loading