Expose server-side dependency evaluator as a public service

Created on 4 September 2025, about 1 month ago

Problem/Motivation

Modules need to evaluate Conditional Fields (CF) dependencies on the server to mirror client-side #states logic (e.g., to enforce "required on publish" rules during validation). Today, the evaluator logic lives in non-public code, so integrators must either:

  • Re-implement the logic, or
  • Copy/paste a private method into their own module.

This creates drift, makes testing harder, and discourages clean integrations (e.g., require_on_publish + Paragraphs + CF). A small, public API would let modules evaluate CF rules without duplication and remain in sync with CF behavior.

Steps to reproduce

  1. Build a validator that must decide, on the server, whether a CF rule with a custom state (e.g., require_on_publish) is currently active.
  2. Attempt to call CF’s dependency evaluation logic directly.
  3. Notice there is no stable, public method/service—your only options are copy/paste or reimplementation.

Proposed resolution

Expose a public, stable, server-side evaluator:

  • Add a container service (and interface), e.g.:
    • conditional_fields.state_evaluator
    • ConditionalFieldsStateEvaluatorInterface::evaluateDependency(string $context, $values, array $options): bool
  • Move the current evaluation logic into the service implementation.
  • Keep the existing helper as a thin wrapper that delegates to the service (preserves BC; document the service as the supported API).
  • Include light unit tests for representative cases (WIDGET/REGEX/AND/OR/XOR/NOT; empty/!empty; checked/!checked; _none handling; int/string casting).

This gives integrators (e.g., require_on_publish) a dependable way to mirror CF decisions on the server without duplicating logic.

Remaining tasks

- [ ] Add interface + service and wire it in *.services.yml.
- [ ] Refactor existing internal calls to use the service (where convenient).
- [ ] Add unit tests for evaluator edge cases.
- [ ] Document example usage for consumers.
- [ ] Changelog/README note about the new public API.

User interface changes

None.

Introduced terminology

State evaluator service: a public service that evaluates Conditional Fields dependencies server-side.

API changes

  • New public service: conditional_fields.state_evaluator.
  • New interface: ConditionalFieldsStateEvaluatorInterface with evaluateDependency().
  • Existing helper method becomes a public delegator (BC preserved); service is the recommended API going forward.

Data model changes

None.

Release notes snippet

Conditional Fields now exposes a public state evaluator service for server-side dependency checks. Modules can call conditional_fields.state_evaluator::evaluateDependency() to mirror #states behavior during validation (e.g., enforcing “required on publish” rules). No UI or configuration changes required.

Feature request
Status

Active

Version

4.0

Component

Compatibility w/ other modules

Created by

🇺🇸United States jcandan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024