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.

CommentFileSizeAuthor
#2 conditional_fields-3193825-2.patch859 bytesprudloff
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
StatusFileSize
new859 bytes

The attached patch fixes the notice.

andreastkdf’s picture

Had 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!

maddentim’s picture

Status: Needs review » Reviewed & tested by the community

I can also confirm the patch resolves the issue and applies cleanly to the 4.0.0-alpha3 release.

grimreaper’s picture

Hi, Thanks for the patch!

liam morland’s picture

Version: 8.x-1.0-alpha9 » 4.x-dev
dqd’s picture

Status: Reviewed & tested by the community » Needs review

Thanks 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.

amstercad’s picture

In 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.

scott_euser made their first commit to this issue’s fork.

scott_euser’s picture

Status: Needs review » Reviewed & tested by the community

I took a look at the logic and the subsequent code really does need the #name - if its missing every bit of the subsequent code falls apart as its essentially the key bit to determine the dependee. So it seems safe to me to merge it @dqd

Moved the patch to an MR for ease of merging, but no change so marking as RTBC

  • dqd committed 25ef661e on 4.x authored by scott_euser
    Issue #3193825 by scott_euser, prudloff: Notice: Undefined index: #name
    
dqd’s picture

Status: Reviewed & tested by the community » Fixed

Oh no, sorry, I missed that one in my notifications. +1 Thanks @scott_euser for clarifying and preparing for merge. Awesome.

@amstercad: this should be solved in one of the Drupal 11 compatibility issues here. At this moment https://www.drupal.org/project/conditional_fields/releases/4.x-dev does not support Drupal 11 yet and so the merge should be made before compatibility issues turn this merge out of sync. I also consider to discuss with other maintainers if we probably move Drupal 11 compatibility temporary to another branch before back porting to not break merging the queue of potentially open and almost fixed issues.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.