Integrate Conditional Fields server-side evaluation for Paragraph subfields

Created on 4 September 2025, about 1 month ago

Problem/Motivation

When require_on_publish (ROP) is used with Paragraphs and Conditional Fields (CF), draft saves can incorrectly fail.

The client-side CF #states marks a Paragraph subfield as “Required on Publish” only when a condition (e.g., a “Gate” checkbox) is true, but the server-side validator does not currently evaluate that CF state or the target publish intent from the submitted form. As a result, an empty Paragraph subfield can be treated as required during a draft save (not publishing), producing “required / required-on-publish” errors that should not block saving.

Steps to reproduce

  1. Create a module to add require_on_publish as a supported state to conditional_fields:
    function MYMODULE_conditionalFieldsStates_alter(array &$states) {
      $states['require_on_publish'] = t('Required on Publish');
    }
        
  2. Create a Paragraph type with a subfield that is required or required-on-publish.
  3. Place that Paragraph field on a moderated node type, along with a "Gate" boolean field.
  4. Add a CF rule for the Paragraph field to be ROP when the "Gate" is checked.
  5. Create a node, check the "Gate", and leave the Paragraph subfield empty.
  6. Save as Draft (do not publish).
  7. Observe server-side validation errors reporting the subfield as required.

Proposed resolution

  • Optional CF integration in ROP:
    • Add a small adapter service in ROP (for example, require_on_publish.state_evaluator) that, when CF is enabled and exposes a public evaluator service, uses it to evaluate CF rules on the server; otherwise fall back to a local shim.
    • In validateParagraphReferenceField(), consult both the subfield’s ROP third-party flag and any CF rules where state === 'require_on_publish', evaluated against posted dependee values.
  • Short-circuit drafts: If the target operation is not publishing, do not add violations for Paragraph children; optionally add a warning when warn_on_empty is set.
  • Harden publish-intent detection: Prefer submitted moderation state or status checkbox over the current live revision.
  • Documentation: Note that core “Required” must be disabled for conditional/ROP subfields; rely on ROP + CF instead of core NotBlank.

Remaining tasks

  • Add the ROP adapter service (shim now; proxy to CF service when available Expose server-side dependency evaluator as a public service Active ).
  • Inject the adapter into the validator; update validateParagraphReferenceField() to honor CF state.
  • Improve publish-intent detection (status/moderation target).
  • Add Kernel tests covering moderated and unmoderated content, draft vs. publish, CF state true/false, and warn vs. violation behavior.
  • Add a Status report line indicating integration mode (Service vs. Shim).
  • Update README/CHANGELOG and inline docs.

User interface changes

None. Optionally, a Status report entry indicating “Conditional Fields integration: Service or Shim”.

Introduced terminology

State evaluator (shim/service): server-side helper to evaluate CF dependency rules for require_on_publish.

API changes

New internal service in ROP (for example, require_on_publish.state_evaluator) used by the validator. Public API of ROP remains unchanged.

Data model changes

None.

Release notes snippet

require_on_publish now optionally integrates with Conditional Fields to evaluate require_on_publish rules on the server for Paragraph subfields. Draft saves no longer fail when those fields are empty; enforcement occurs only on publish. If Conditional Fields dependency evaluator service is not available, ROP uses a local shim. For conditional/ROP subfields, leave core “Required” unchecked and rely on ROP + CF.

Feature request
Status

Active

Version

2.1

Component

Code

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