Problem/Motivation
In some situations, the #parents key may be empty in a form element, resulting in an error (possibly only in combination with inline form errors). This will now result in a TypeError:
TypeError: implode(): Argument #1 ($array) must be of type array, string given in implode() (line 26 of core/lib/Drupal/Core/Form/FormElementHelper.php).
Steps to reproduce
At least one situation where this happens can be triggered using config overrides:
- Enable inline form errors (unsure if this is required at this point)
- Override a setting from system.site in settings.php, e.g. $config['system.site']['name'] = 'Overridden site name';
- Visit /admin/config/system/site-information
- Notice the overridden message at the top, informing you of the overridden value
- Make a change to the form and save
- Notice the error
Proposed resolution
TBD.
Remaining tasks
- Debug
- Propose resolution
- Fix
User interface changes
None.
API changes
None.
Data model changes
None.
Original report
Seeing this Notice when saving a node edit form:
Notice: Undefined index: #parents in /app/core/lib/Drupal/Core/Form/FormElementHelper.php.
Comments
Comment #2
brooke_heaton commentedComment #3
brooke_heaton commentedAttached patch adds isset check on #parents.
Comment #4
cilefen commentedComment #8
smustgrave commentedThis will require an issue summary update.
I have not seen this error when saying a node so need steps to reproduce.
Comment #10
s_leu commentedThe problem this patch is addressing was throwing only notices on PHP 7.4 but is throwing errors on PHP 8+, so the patch is valid I think. Steps to reproduce this using the focal_point module:
On Vanilla Drupal 9.5+
There will be an ajax error originating from the location in code the patch here changes.
Comment #11
smustgrave commentedIf valid it will need a test case to show the issue.
Though not sure that’s a fix that would get committed. This may be covering a symptom of a bigger issue. Like why is that value not set when it gets to this point?
But either way tests will 100% be needed
Comment #12
szato commentedMaybe related to Focal point image widget causes validation errors not to be shown?
Comment #14
hargurpreet commentedUpdated patch #3 to fix a notice in core/lib/Drupal/Core/Form/FormState.php on line 1174
Comment #15
pixlkat commentedI also was seeing this error, but with different form elements. We have a taxonomy entity reference field with unlimited cardinality, and we are using inline entity form to add an existing term. We are also using Inline Form Errors to display error messages inline.
When submitting the IEF form with an error condition, it appears that the `actions` element was the form element causing the error. This issue was not present when using IEF to add a new entity.
Applying the patch in #14 fixed the error in our case.
Comment #16
dahousecat commentedI was getting this error on /admin/config/development/performance with $key config_override_status_messages which comes from Drupal\Core\Form\ConfigFormBase.
Patch #14 applied and resolved the issue for me.
Comment #17
devdits commentedWe did have create a small patch to fix the problem:
But it's doing almost the same as #14.
Comment #19
driskell commentedI had this same problem with config overrides key as well on people account settings area.
So not sure if possible there's a reproduction case there with config overrides applying. Specifically for me it was relaying to symfony_mailer module I think that brings in some overrides there, and then when saving that form it now crashes in 11.1
Comment #20
eelkeblokLooks like this may be happening in different situations, so the risk is that we'll be solving one reason #parents is not set, and there may be others. Also, it looks like this is now an error in later PHP versions and will be reported like this:
[Sorry, apparently forgot to paste the error, or maybe it got filtered out somehow. Either way, it has now been lost to the depths of time...].
Comment #21
eelkeblokComment #22
dabbor commentedWe ran into the same problem while using Paragraphs and Media which always gives us following Warning and Error in the exact order:
-
Warning: Undefined array key "#parents"-
TypeError: implode(): If argument #1 ($separator) is of type string, argument #2 ($array) must be of type array, null given in implode()Here are our replication steps: