Problem/Motivation
Conditional Fields combines dependencies for different target states during server-side submit handling.
A target field can legitimately have complementary states, for example:
- Visible when a checkbox is unchecked.
- Emptied when the same checkbox is checked.
Client-side states keep those rules separate. Server-side evaluation does not.
ConditionalFieldsFormHelper::evaluateDependencies() groups dependency results by AND/OR/XOR without also separating them by target state.
That causes submit-time reset handling to evaluate unrelated states together.
For example:
visiblewhen!checked, withreset: trueemptywhenchecked
With both in the AND group, saving while the checkbox is unchecked evaluates effectively as:
TRUE AND FALSE = FALSEThe target is then treated as untriggered and reset to its default value even though its Visible condition is active.
This is not reliably fixable by changing grouping. Functional coverage across all AND/OR/XOR combinations shows that configurations which preserve the value in one state can fail to reset it in the opposite state.
Steps to reproduce
- Create a boolean Control field and a Target field with a default value.
- Add a dependency to Target:
- State: Visible
- Condition: Control is unchecked
- Grouping: AND
- Enable "Reset the target to its default values when the form is submitted if the dependency is not triggered."
- Add another dependency to Target:
- State: Emptied
- Condition: Control is checked
- Grouping: AND
- Leave Control unchecked.
- Enter a non-default value in Target.
- Save.
- Observe that Target is reset to its default value even though its Visible condition is triggered.
Proposed resolution
Keep dependencies for different target states separate during server-side evaluation.
Submit-time reset behavior should be evaluated against the dependency or state where reset is configured. A dependency for another state such as empty should not affect whether a visible dependency is considered triggered.
Update ConditionalFieldsFormHelper::evaluateDependencies() and related reset handling so server-side behavior matches the state separation already used for client-side Drupal states.
Add functional coverage for the full AND/OR/XOR matrix across complementary visible and empty states.
Remaining tasks
Add failing functional test coverage.- Fix server-side dependency evaluation so target states remain separate.
- Confirm existing single-state grouping behavior remains unchanged.
User interface changes
None.
API changes
No public API changes expected.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | conditional_fields-server-side-dependency-grouping-3629120-4.patch | 10.99 KB | jcandan |
Issue fork conditional_fields-3629120
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 #3
jcandan commentedFunctional test coverage of all nine AND/OR/XOR grouping combinations confirms both failure modes:
18 tests, 180 assertions, 9 failures is consistent with the matrix:
So PHPUnit reports 18 test cases total.
The 180 assertions means each case is doing about 10 assertions on average, including setup/state checks plus the final saved-value assertion.
The 9 failures are exactly the behavioral failures we care about:
So half the matrix fails, which makes the defect very apparent.
Comment #4
jcandan commentedComment #5
jcandan commented