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.
Problem/Motivation
If a form widget contains an element that does not have a #name
key (for example, a container), it triggers this notice:
Notice: Undefined index: #name
in ConditionalFieldsFormHelper.php line 192
Steps to reproduce
/**
* @param $form
*/
function mymodule_form_alter(&$form) {
$form['field_my_field']['widget'][0]['foo'] = [
'#type' => 'container',
'bar' => [],
];
}
Proposed resolution
ConditionalFieldsFormHelper::getState()
should check if the #name
key exists.
Remaining tasks
I will submit a patch.
Comment | File | Size | Author |
---|---|---|---|
#2 | conditional_fields-3193825-2.patch | 859 bytes | prudloff |
|
Comments
Comment #2
prudloff CreditAttribution: prudloff at Insite commentedThe attached patch fixes the notice.
Comment #3
andreastkdf CreditAttribution: andreastkdf as a volunteer and at Soapbox Communications Ltd commentedHad the same notice for a form widget containing an element that does not have a #name key.
I can confirm too that #2 fixes the notice
Thanks!
Comment #4
maddentim CreditAttribution: maddentim commentedI can also confirm the patch resolves the issue and applies cleanly to the 4.0.0-alpha3 release.
Comment #5
GrimreaperHi, Thanks for the patch!
Comment #6
Liam MorlandComment #7
dqdThanks for the reports and all working on this here! +1
It may solve the issue of the thrown error, but I am not sure if we should leave out ELSE completely here. Now we have IF and ELSE IF and nothing if both are not TRUE. Can somebody confirm that it is harmless and that we do not need a silent exception error or anything else to notify? Or ion other words: do we need #name? If not, why we asking for it then?
Otherwise if somebody can clarify this for me I do not see reasons not to commit. I would commit/merge it asap after another review of my question.
Comment #8
AmstercadIn preparation for Drupal 11, please note the test failure of the current patch:
PHP 8.3 & MySQL 8, D10.2 Patch Failed to Apply
Drupal 11 requires PHP 8.3.