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
- Create List (text) field
field_project_categorywith 3 values and allowed number of values to 1 - Create field Attachments
field_attachments. -
Create dependency:
Target field:field_attachments
Controlled by:field_project_category
Proposed resolution
check if $options['regex'] isset
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3443731-3.patch | 685 bytes | luk.tc |
| Screenshot from 2024-04-26 14-18-23.png | 66.78 KB | luk.tc |
Issue fork conditional_fields-3443731
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
Comment #2
abhishek_gupta1 commentedComment #3
luk.tc commentedComment #5
abhishek_gupta1 commentedabove patch will work only for tag 4.0.0-alpha5. I created MR for branch 4.x. please review it once
Comment #6
luk.tc commentedComment #7
arthur.baghdasar commentedWorks for me thank you
Comment #9
joelpittetMoving 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.
Comment #10
joelpittetSmaller title
Comment #11
joelpittetThanks all. Committed to 4.x.
The warning was reproducible:
regexwas missing from both the condition defaults and config schema, so some saved dependencies could reachevaluateDependency()without that key.The fix completes dependency settings centrally instead of guarding the single read:
regexto the schema and default settings.attachDependency()merge defaults into every dependency.I reverted the MR's
isset() && !empty()guard because it becomes redundant, andempty()would incorrectly reject0as 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.