Needs work
Project:
Drupal core
Version:
main
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
21 Jan 2019 at 09:27 UTC
Updated:
27 Apr 2026 at 21:15 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
nmitev commentedThese seems to fix the Notices and Warnings.
Comment #3
nmitev commentedComment #4
nmitev commentedComment #5
malcolm_p commentedI've also run into this error when using inline_form_errors with elements such as
html_tagorcontainer. This patch fixed the issue for me as well.Comment #6
dennis cohn commentedalso works for me!
Comment #7
dennis cohn commentedComment #8
skaughthopefully tag will help gain attention.
Comment #9
tim.plunkettThis could use some automated tests.
Curious about the steps to reproduce this one, could you expand on that in the issue summary?
Comment #10
skaughtFor my case: error has appeared after #after_build using in a custom module.
True MODULE name starts with 'b' --> after_build is being used instead of alter module weights in order to change form labels..
other active contrib modules (with related form alters)
Comment #11
afschThe patch in #2 worked fine. About the #10, I confirm it appears using #after_build in a custom module, in my case I used for user registration.
Comment #12
ravi.shankar commentedDone this patch on Drupal 8.8.x-dev
Comment #13
ravi.shankar commentedComment #14
bnjmnmSetting back to needs work as this still needs test coverage, but I may have something that will help move that along.
The patch I added to #3076171: Provide a new library to replace jQuery UI autocomplete will fail
\Drupal\Tests\comment\Functional\CommentAnonymousTest::testAnonymousunless I also apply the patch from #13The attached patch does not have #13 applied, so it can be used as a reference to help create a failing scenario in a test.
Comment #15
wim leers"without yalls"? :D
Comment #16
skaughtpatch in #14 has nothing to do with this issue. look like it's from the switch JQ autocomplete to awesomplete.
Comment #17
bnjmnm#16
The patch provided in #14 creates a condition that fails unless the patch from #12 in this issue is applied. Since this issue doesn't currently have steps to reproduce or tests (which it needs before it can be committed), I thought that it may be helpful to have that as a reference. Perhaps there are already tests and steps to reproduce on on the way and this is not helpful.
Comment #18
skaughti do hear what you mean to provide but that.. but, if you comfortable with the test framework could you provide the test for that instead?
i know: starting with a test -- it's crazy (:
Comment #21
joseph.olstadpatch 12 resolves my issue, developing safedelete module to check for references (linkit links) before deleting or archiving content, adding an error to the node form by using setError , the form is modified by another module called entity_translation_unified_form
patch 12 takes care of the noise about "#parent"
Comment #22
renrhafPatch #12 makes the warning disappear properly
Comment #23
ptmkenny commentedI'm getting this issue with Drupal Commerce/Address and the patch in #12 does not fix the issue.
Steps to reproduce
1. Install a basic Commerce setup. Use Commerce Stripe as the payment module.
2. Configure the billing Profile to only take a postal code.
3. Put a product in the card and go to checkout.
4. On the checkout form, enter an incorrect zip code and press to confirm the order.
The page will be flooded with errors like this:
Comment #25
prudloff commented!empty()does not prevent the notice for me. This patch usesisset()instead.Comment #26
johnpitcairn commentedThe patch at #12 fixes the issue for me on an install of D9.1.2 when validating commerce address fields, which have been modified via an #after_build callback.
However it does not fix what appears to be the same issue when validating commerce_stripe card fields. The patch at #25 does not fix that either.
Comment #27
norman.lolThe patch in #12 is the same as in #2.
Though only the patch from #25 with the
isset()fixed it for me.Comment #28
lamp5The same warning when using Multiple Registration module but patch from #12 works. Thx.
Comment #29
skaughtComment #30
catchPer the tag this still needs test coverage.
Comment #32
andyg5000Hey Everyone,
It looks like this happens when a form alter adds elements to the form during #after_build hooks as mentioned above. Manipulating existing elements does not cause any issues because `#parents` are already set for elements defined during the initial build. Here are 2 patches (fail/pass) to hopefully move this issue along. I'm happy to make adjustments to these as necessary since I don't have any core commits yet ;)
Comment #33
andyg5000PHPCS!
Comment #34
andyg5000Comment #37
andyg5000I'll investigate the 17 failures above :(
In the meantime, it looks like anywhere the following code is executed could be problematic (7 core instances). We need to determine if `#parents` should always exist, or if we should check the existence of it before performing array operations on it.
Related. #3150967
Comment #38
andyg5000Here's an updated patch that should pass. I'm not sure why my approach (isset or !empty at beginning of function) fails test because I can't tell the difference. Anyway, the approach in #25 passes, so we'll stick with that!
Comment #39
andyg5000Comment #40
lucasrossi commentedTested patch #38 on Core 9.2.6 in a Form API with Address module and it's working fine.
Comment #41
joseph.olstadNicely done @andyg5000
might be helpful to provide a tests-only patch to confirm that core fails without the fix.
Comment #42
lucasrossi commentedConfirming patch #38 is working on Core 9.2.6 with Address module enabled.
Comment #43
joseph.olstadComment #44
joseph.olstadComment #45
joseph.olstadweird I don't see the RTBC status after NR status, just going to set it to NR, then RTBC.
Comment #46
joseph.olstadRTBC patch 38
Comment #47
tim.plunkettComment #40 was unpublished for some reason.
Comment #48
tim.plunkettHad a couple tweaks to make, so I did it in an MR.
Comment #50
alexpottThis fix feels odd. Elements added in after build not only lack #parents they also lack #array_parents, #tree, #weight and lots of other stuff added by \Drupal\Core\Form\FormBuilder::doBuildForm(). Do we need to improve the documentation in \Drupal\Core\Form\FormBuilderInterface::doBuildForm() about added new elements there as I can imagine it is quite easy to break things?
Also going to comment on the MR.
Comment #52
joseph.olstadThis branch from the merge request 1300 still applies cleanly to 9.3.x and 9.4.x
https://git.drupalcode.org/project/drupal/-/merge_requests/1300.diff
Comment #54
bwoods commentedConfirming patch #38 is working on Core 9.4.2 with Address module enabled.
Comment #55
johnpitcairn commentedThe current patch fixes
FormState::getError(), but I think a similar problem exists forFormState::setError(). This can be triggered by address field in the same way. Keep ajax-switching the country to/from something that doesn't have one of the displayed address fields and you'll get there.A simple
$element['#parents']guard condition insetError()also fixes this, but makes me nervous as per #50 and #37.Comment #56
qusai taha commentedI have the same issue also when trying to upload media through the media library pop up and with empty Alternative text
Comment #57
qusai taha commentedI have the same issue also when trying to upload media through the media library pop up and with empty Alternative text
Comment #59
JeremyFrench commentedThis issue surfaced for me after updating a site to PHP8. I think the issue pre-existed but was harmless in php7.4
The patch in #57 applies cleanly and solves the issue. It also triggers what would be the error state in tests.
So long as the tests pass, I can't see a reason why this is not good to go.
Comment #60
alexpottThe test coverage from the MR has been removed from the latest patches. #57 claims the patch will trigger an error in tests but I can't see how. Happy to be wrong.
FWIW the MR still applies to 10.1.x and can be rebased on 9.5.x so we really should be using the MR and not adding new patches to an issue.
Comment #62
heikkiy commentedWe also encountered this error after updating core to 9.5.10 and PHP 8.1. I don't remember seeing the error with PHP 8.0.
In our case we seem to get two different warnings:
Comment #65
recrit commentedI created a new branch and MR 5230 for 11.x. This branch also addresses the 2 threads on the original MR 1300:
Comment #66
recrit commentedhiding outdated patches
Comment #67
recrit commentedAttached is a static patch of the MR 5230 at commit 2c405b97. This can be used for consistent composer builds.
Comment #69
smustgrave commentedRebased and ran test-only feature for MR 5230. https://git.drupalcode.org/issue/drupal-3027240/-/jobs/272556
They passed when they should have failed.
Comment #70
recrit commented@smutsgrave I suspect it is how you are testing the "test only". The changes in
core/modules/system/tests/modules/form_test/form_test.moduleare needed for the test but the job https://git.drupalcode.org/issue/drupal-3027240/-/jobs/272556 is reverting that change (see screenshot attached).Comment #71
recrit commentedattached is a tests only patch of MR5230 at commit 2c405b97. This should fail.
Comment #72
smustgrave commentedThanks for the test-only patch. It indeed does show the failure so removing the tests tag.
Change seems fine and hate to do it but could the issue summary be updated also. Solution "Apply patch" isn't a real solution description and could be kicked back just for that. Issue summary is to help the committer understand the issue and what the fix is.
Thanks!
Comment #73
recrit commentedComment #74
smustgrave commentedThanks!
Comment #75
quietone commentedI'm triaging RTBC issues. I read the IS and the comments.
I think the following still need to be answered
#50
#37
and are mentioned in #55 as a point of concern.
I am setting to needs work for those items.
Comment #76
luke.leberFWIW - I managed to stumble in here while trying to add an error to an
#type => 'item'FAPI element. My particular case (heavy in custom code territory) is that I have a third party javascripty thing (reCAPTCHA) that needs to block form submit in certain cases.I wonder -- are there certain FAPI element types that simply weren't intended to support error messages associated with them?
Comment #77
pbabin commentedRan into an issue today that triggered this. The patch from MR! 1300 fixed our issue.
Comment #78
joseph.olstadThe code that fixes this was vastly simplified since comments #50, #55 and #37 effectively deprecating those comments.
The fix is a very simple change with an automated test that has a proven test only failure in the above comment and the justification is explained by the issue summary
On our team, it was noticed when running the safedelete module along with the entity_translation_unified_form module
Comment #83
alexpottAdded some questions/comments to the MR
Also #55 is not addressed in comments.
Also #50 is not really addressed either - i.e. the part about what the form system adds to all elements by default and will be missing if you add elements in after build.
Comment #84
kriboogh commentedAdded patch of MR5230 for use in composer.
Applies to 11.x and 10.3.x
Comment #85
murzGot the same issue in another place, in the function ConfigFormBase::checkConfigOverrides() when it creates a warning message that some values are overridden:
Just posting here to help search for the source of this warning.
Comment #86
aunva patch for Drupal 11.2.2
Comment #88
driskell commentedSimilar issue in https://www.drupal.org/project/drupal/issues/3151865 that also patches this error
Comment #91
ankondrat4 commentedFixed phpcs and updated FormAfterBuildTest, please review.
Comment #92
ankondrat4 commentedComment #93
smustgrave commentedLeft some comments on the MR.
Comment #94
recrit commentedstatic patch for composer builds.
Comment #95
damienmckennaFYI I ran into this when adding a custom constraint on an entity reference field:
(code comments removed for brevity)
The custom constraint:
The custom constraint validator:
When I hit the save button on the node form it throws the error.