Add require on publish as a conditional field option

Created on 17 June 2025, 11 days ago

Problem/Motivation

Add support for working with Conditional Fields β†’ .

Proposed resolution

Conditional Fields is a popular module in the community. It would benefit those who wish to require on publish fields dependent upon other field status.

✨ Feature request
Status

Active

Version

1.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States jcandan

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

Merge Requests

Comments & Activities

  • Issue created by @jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    I've pushed a couple of commits to the fork (noting here in case someone overrides):

    I am still working through some issues:

    1. I think I need to prevent error message removal when the condition is not met in \Drupal\conditional_fields\ConditionalFieldsFormHelper::formValidate().
    2. It seems the dependentValidate() thinks the condition is "triggered" when it is not.
    3. The dependentValidate() also seems to be explicitly handling required and !required.
    4. Not yet sure if it is best to pass the _wrapper in the error key.
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    Fork description

    So that the module doesn't depend on Conditional Fields, the logic is provided in a submodule. When enabled, it provides require_on_publish as one of the possible #states.

    Steps to reproduce

    Using the provided fork, you may begin to understand how this might work.

    1. Install Require on Publish and Conditional Fields.
    2. Add a boolean field to Basic Page, and a text field.
    3. Under Structure > Conditional Fields, make the text field required on publish when the boolean field is checked.
    4. Create a Basic Page.

    With the above and the branch as it stands, the required on publish markings are successfully applied. However, the error handling still needs work.

    Problems persist

    See comment above and comments in code for an understanding of the ongoing problems.

  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    By adding full support for #states Form API conditions, integration with Conditional Fields β†’ is possible with:

    use Drupal\Core\Form\FormStateInterface;
    
    /**
     * Implements hook_conditionalFieldsStates_alter().
     *
     * @see Drupal\conditional_fields\Conditions::conditionalFieldsState
     * @phpcs:disable Drupal.NamingConventions.ValidFunctionName.InvalidName
     */
    function require_on_publish_conditional_conditionalFieldsStates_alter(array &$states) {
      // phpcs:enable
      // A list of supported states that may be applied to a conditional field.
      $states['require_on_publish'] = t('Required on Publish');
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States jcandan
  • Pipeline finished with Failed
    2 days ago
    Total: 156s
    #531506
  • Pipeline finished with Failed
    1 day ago
    #532413
  • Pipeline finished with Failed
    1 day ago
    #532437
  • Pipeline finished with Failed
    1 day ago
    #532441
  • Pipeline finished with Failed
    1 day ago
    #532458
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    Rolled MR !24 into a stable patch file.

  • πŸ‡ΊπŸ‡ΈUnited States jcandan
Production build 0.71.5 2024