Closed (fixed)
Project:
Drupal core
Version:
9.2.x-dev
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Dec 2010 at 10:00 UTC
Updated:
1 Nov 2021 at 14:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
sunShould have used #after_build instead of #process.
Comment #2
mr.baileysStill getting notices after applying the patch, but now in the
after_build()function:For reference, here's the partial/shortened form I'm using:
Comment #3
sunI see, let's try this one instead.
Comment #4
mr.baileysNope, sorry:
Comment #5
sunhm... so it actually would have to be a #pre_render, but still needs access to $form_state, and that callback would have to be invoked before either of both elements is attempted to be rendered... very tricky. :-|
Comment #6
dwightaspinwall commentedSubscribing. Happened to me too; confusing until I saw this issue.
Comment #7
polIf you manually add the '#id' to the machine name and the field in 'source', the error is gone.
Comment #8
sunComment #9
torotil commentedIn D7 this also leads to a JS error: The empty #id is put into Drupal.settings.machineName and the behavior then tries to do a $('#', …) which throws a syntax error.
Comment #13
taggartj commentedStill having this issue in a config entity form (8.3.4)
but if you put the machine_name field above the you get the "label" notice:
"Notice: Undefined index: #id in Drupal\Core\Render\Element\MachineName::processMachineName() (line 174 of core/lib/Drupal/Core/Render/Element/MachineName.php). "
Comment #14
tim.plunkettI don't see any realistic approach to fixing this. I think we need to inform the developer that they must define the form elements in the correct order.
Comment #17
nortmas commentedI've added a new field in the custom module through the yml file for the
commerce_storeentity which doesn't implement field api.Despite the fact that I've added
wightproperty intocore.entity_form_display.commerce_store.online.default.ymlit doesn't affect anything and I still see this error, however, themachine_namefield is placed aftersourcefield.Unfortunately, I don't see any approach to change the render order in this case.
Maybe someone knows how to fix it?
Comment #18
borisson_I think #17 is a different problem. I agree with #14 on this being really hard to solve in a good way and that this is a good fix. We should get a test for this as well, to make sure we don't regress the new behavior.
Comment #25
lendudeHere is a test for the new thrown exception. I've modified the message a bit to specify that you can also set an id on the source element to work around the problem.
The test-only patch test is a little different than the one with the fix but it illustrates the notice that gets thrown.
Comment #26
lendudefix the cs fail
Comment #29
lendudeFix the test
Comment #30
joachim commentedIs this always true? Would this exception also be thrown if the source element was missing from the form?
Comment #31
lendude@joachim there is a guard statement for that before reaching this logic
So no, it won't be thrown in that case.
Comment #32
joachim commentedThanks! In which case, happy to say RTBC.
Comment #33
alexpottCommitted and pushed 25718d36d4 to 9.3.x and 4ba14b66af to 9.2.x. Thanks!