- Issue created by @marcusx
- ๐ฎ๐ณIndia kulpratap2002
I have solved the error and generated MR.
The reason
$form_element = FormElementHelper::getElementByName([$key], $form);
or$form_element = FormElementHelper::getElementByName(['submitted', $child_key], $form);
does not work is because getElementByName() in Drupal core only accepts a string as its first argument, not an array.Core internally compares this string against the elementโs
#parents
array, joined withimplode('][', โฆ)
. Passing an array directly causes a PHP type error:
TypeError: Argument 1 ($name) must be of type string, array given
The correct approach is to convert any array of parent keys into a string before passing it, like this:
$form_element = FormElementHelper::getElementByName(implode('][', ['submitted', $child_key]), $form);
This ensures compatibility with both flat and nested form elements (Webforms, nodes, user profiles, etc.) without touching core.Also, I have fixed this Issue ๐ webform file document field generates php TypeError caused by protected forms module Active .
Please review.
Thanks