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:

  • visible when !checked, with reset: true
  • empty when checked

With both in the AND group, saving while the checkbox is unchecked evaluates effectively as:

TRUE AND FALSE = FALSE

The 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

  1. Create a boolean Control field and a Target field with a default value.
  2. 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."
  3. Add another dependency to Target:
    • State: Emptied
    • Condition: Control is checked
    • Grouping: AND
  4. Leave Control unchecked.
  5. Enter a non-default value in Target.
  6. Save.
  7. 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.

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

jcandan created an issue. See original summary.

jcandan’s picture

Issue summary: View changes

Functional test coverage of all nine AND/OR/XOR grouping combinations confirms both failure modes:

Visible Empty Visible triggered Visible untriggered
AND AND Incorrectly reset Correct
AND OR Incorrectly reset Correct
AND XOR Incorrectly reset Correct
OR AND Incorrectly reset Correct
OR OR Correct Incorrectly preserved
OR XOR Incorrectly reset Correct
XOR AND Incorrectly reset Correct
XOR OR Incorrectly reset Correct
XOR XOR Correct Incorrectly preserved

18 tests, 180 assertions, 9 failures is consistent with the matrix:

  • 9 grouping combinations
  • 2 scenarios per combination:
    • visible condition triggered
    • visible condition untriggered

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:

  • 7 cases incorrectly reset when the visible condition is triggered
  • 2 cases incorrectly preserve when the visible condition is untriggered

So half the matrix fails, which makes the defect very apparent.

jcandan’s picture

jcandan’s picture

Assigned: jcandan » Unassigned
Status: Active » Needs review