Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you add a form element of type machine_name
and the source element for the machine name element is defined after the machine name element itself, notices are thrown upon submitting the form:
* Notice: Undefined index: #id in form_process_machine_name() (line 3293 of /home/mrbaileys/workspace/Drupal-7-HEAD/includes/form.inc).
* Notice: Undefined index: #id in form_process_machine_name() (line 3306 of /home/mrbaileys/workspace/Drupal-7-HEAD/includes/form.inc).
Comment | File | Size | Author |
---|---|---|---|
#29 | 990218-29.patch | 3.6 KB | Lendude |
#29 | interdiff-990218-26-29.txt | 944 bytes | Lendude |
#26 | 990218-26.patch | 3.6 KB | Lendude |
#25 | 990218-25.patch | 3.62 KB | Lendude |
#25 | 990218-25-TEST_ONLY.patch | 1.93 KB | Lendude |
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 CreditAttribution: 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 CreditAttribution: torotil at more onion 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 CreditAttribution: 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 CreditAttribution: nortmas commentedI've added a new field in the custom module through the yml file for the
commerce_store
entity which doesn't implement field api.Despite the fact that I've added
wight
property intocore.entity_form_display.commerce_store.online.default.yml
it doesn't affect anything and I still see this error, however, themachine_name
field is placed aftersource
field.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 CreditAttribution: joachim as a volunteer 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 CreditAttribution: joachim as a volunteer 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!