Problem/Motivation

Warning: Undefined array key "regex" in Drupal\conditional_fields\ConditionalFieldsFormHelper::evaluateDependency() (line 793 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php).

Steps to reproduce

  1. Create List (text) field field_project_category with 3 values and allowed number of values to 1
  2. Create field Attachments field_attachments.
  3. Create dependency:
    Target field: field_attachments
    Controlled by: field_project_category
    Condition

Proposed resolution

check if $options['regex'] isset

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

lukasz.tyc created an issue. See original summary.

abhishek_gupta1’s picture

Assigned: Unassigned » abhishek_gupta1
luk.tc’s picture

StatusFileSize
new685 bytes

abhishek_gupta1’s picture

Assigned: abhishek_gupta1 » Unassigned
Status: Active » Needs review

above patch will work only for tag 4.0.0-alpha5. I created MR for branch 4.x. please review it once

luk.tc’s picture

Version: 4.0.0-alpha5 » 4.x-dev
arthur.baghdasar’s picture

Status: Needs review » Reviewed & tested by the community

Works for me thank you

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

joelpittet’s picture

Status: Reviewed & tested by the community » Needs review

Moving this back to Needs review, because patches don't get tests run against them.

I added some tests (and a bit of scope creep 9f2704bf ). The schema was missing for regex 05aedf95 .

Also added some tests. I am thinking of adding more to this issue but I think we need a helper for empty values because it touches a number of spots in the code.

joelpittet’s picture

Title: Warning: Undefined array key "regex" in Drupal\conditional_fields\ConditionalFieldsFormHelper::evaluateDependency() (line 793 of modules/contrib/conditional_fields/src/ConditionalFieldsFormHelper.php). » Warning: Undefined array key "regex" in ConditionalFieldsFormHelper::evaluateDependency()

Smaller title

joelpittet’s picture

Status: Needs review » Fixed

Thanks all. Committed to 4.x.

The warning was reproducible: regex was missing from both the condition defaults and config schema, so some saved dependencies could reach evaluateDependency() without that key.

The fix completes dependency settings centrally instead of guarding the single read:

  • Add regex to the schema and default settings.
  • Have attachDependency() merge defaults into every dependency.

I reverted the MR's isset() && !empty() guard because it becomes redundant, and empty() would incorrectly reject 0 as a valid pattern.

Regression and config schema coverage added; full suite passes (and fails with tests only run).

Thanks @abhishek_gupta1 for the MR, @luk.tc for the clear reproduction steps, and @arthur.baghdasar for confirming.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.