Problem/Motivation

TypeError: Drupal\conditional_fields\ConditionalFieldsFormHelper::elementAddProperty(): Argument #1 ($element) must be of type array, null given, called in /app/docroot/modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php on line 194 in Drupal\conditional_fields\ConditionalFieldsFormHelper->elementAddProperty() (line 843 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).
Drupal\conditional_fields\ConditionalFieldsFormHelper->processDependeeFields(Array, NULL, Array, Array) (Line: 111)
Drupal\conditional_fields\ConditionalFieldsFormHelper->processDependentFields() (Line: 85)
Drupal\conditional_fields\ConditionalFieldsFormHelper->afterBuild(Array, Object) (Line: 187)
conditional_fields_form_after_build(Array, Object)
call_user_func_array('conditional_fields_form_after_build', Array) (Line: 1084)
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

blade_ukraine created an issue. See original summary.

blade_ukraine’s picture

StatusFileSize
new580 bytes
blade_ukraine’s picture

Title: Field array cannot be get id. » Field data array cannot be retrieved from form array by field name.
blade_ukraine’s picture

Fixed patch to the latest module changes.

blade_ukraine’s picture

Status: Active » Needs review

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

benstallings’s picture

Status: Needs review » Reviewed & tested by the community

Simple defensive guard. If NestedArray::getValue() returns NULL or empty array (field not found in the form tree), skip it instead of passing it into processDependeeFields() where it would cause errors.

This can happen when a dependency references a field that exists in config but isn't rendered on the current form (e.g. hidden by another module, removed by form alter, or a paragraph field at a delta that doesn't exist yet).

Verdict: Clean, safe, correct. Good to merge.

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

joelpittet’s picture

Title: Field data array cannot be retrieved from form array by field name. » Field data array cannot be retrieved from form array by field name
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

@benstallings The analysis is sound, and thanks for the MR.
I want to make sure we are guarding the right thing though so it would be good to have a regression test to ensure we are really fixing something (and haven't already fixed it in a different way given the commits I have made recently).

So +1 to the fix, a small regression assertion with a red/green tests-only run would nail this shut.

@blade_ukraine Thanks for writing up the patch.