Require on Publish
Allows fields to be marked as required only when content is being published, rather than always required.
require_on_publish
Install
composer require 'drupal/require_on_publish:^2.0'
composer require 'drupal/require_on_publish:8.x-1.11'
Overview
The Require on Publish module provides a mechanism for requiring a field to be filled out only when publishing an entity. This is particularly useful for editorial workflows where content authors need to save drafts without completing all fields, but must fill in specific fields before the content can be published.
When enabled for a field, validation errors will only appear when attempting to publish the content. If the content is saved as a draft (unpublished), the field can remain empty without triggering validation errors. The module also provides an optional "Warning on Empty" feature that displays warning messages when saving drafts with empty fields, reminding authors that these fields will be required upon publishing.
The module integrates seamlessly with Drupal's Content Moderation module, correctly detecting publish states from editorial workflows. It also supports the Paragraphs module, allowing fields within paragraphs to be marked as required on publish.
Features
- Mark any field as 'Required on Publish' through field configuration UI
- Visual indicator (blue triangle) distinguishes 'required on publish' fields from always-required fields
- Optional 'Warning on Empty' feature displays warnings when saving drafts with empty required-on-publish fields
- Full integration with Content Moderation module and editorial workflows
- Support for Paragraphs module - fields within paragraphs can be marked as required on publish
- Automatic mutual exclusivity between 'Required' and 'Required on Publish' settings via JavaScript
- Works with any entity type that implements EntityPublishedInterface (nodes, media, etc.)
- Support for various field types including text, entity references, boolean, datetime, and more
Use Cases
Editorial Workflow with Draft Content
News organizations often need reporters to save incomplete articles as drafts. Using 'Require on Publish', fields like 'Featured Image', 'Summary', or 'Category' can be left empty during drafting but must be filled before the article can be published. This allows flexible content creation while ensuring published content meets quality standards.
Content Moderation Integration
When using Content Moderation with states like 'Draft', 'In Review', and 'Published', the module correctly detects when content transitions to a published state. Fields marked as 'require on publish' will only trigger validation errors when moving content to the published state, not during draft or review stages.
Warning System for Incomplete Drafts
Enable both 'Required on Publish' and 'Warning on Empty' for important fields. When saving a draft with empty fields, authors see warning messages reminding them which fields need to be completed before publishing. This helps editors track incomplete content without blocking the save operation.
Paragraphs with Required Fields
For complex content structures using Paragraphs, individual fields within paragraph types can be marked as required on publish. For example, a 'Product Feature' paragraph might have a 'Feature Description' field that's required only when the parent product page is published.
Tips
- Use 'Warning on Empty' in combination with 'Required on Publish' to help editors track incomplete content without blocking saves
- The visual indicator (blue triangle) helps distinguish 'required on publish' fields from always-required fields (red asterisk)
- When both 'Required' and 'Required on Publish' are checked, the JavaScript automatically unchecks the other option - they are mutually exclusive
- The module works with any entity type implementing EntityPublishedInterface, not just nodes
Technical Details
Admin Pages 1
/admin/structure/types/manage/{node_type}/fields/{field_config}
When editing any field configuration for publishable entity types (nodes, media, etc.), two new checkboxes appear that allow administrators to configure the require-on-publish behavior for that specific field.
Hooks 9
hook_form_field_config_edit_form_alter
Adds the 'Required on Publish' and 'Warning on Empty' checkboxes to field configuration edit forms for publishable entity types.
hook_entity_type_alter
Adds the 'require_on_publish' validation constraint to all entity types that implement EntityPublishedInterface.
hook_form_alter
Adds visual indicators (CSS classes) to form widgets for fields that have 'require on publish' enabled.
hook_preprocess_form_element
Adds the 'form-required-on-publish' CSS class to form element labels.
hook_preprocess_fieldset
Adds the 'form-required-on-publish' CSS class to fieldset legend spans.
hook_preprocess_datetime_wrapper
Adds the 'form-required-on-publish' CSS class to datetime wrapper elements.
hook_preprocess_field_multiple_value_form
Adds the 'form-required-on-publish' CSS class to multi-value field table headers.
hook_field_widget_entity_reference_paragraphs_form_alter
Adds require-on-publish indicators to paragraph widget elements.
hook_field_widget_single_element_paragraphs_form_alter
Adds require-on-publish indicators to single-element paragraph widgets.
Troubleshooting 4
This checkbox only appears for entity types that implement EntityPublishedInterface. Verify that your entity type (nodes, media, etc.) supports publishing. Custom entity types must implement this interface.
Ensure the content is actually being saved as unpublished. Check that the 'Published' checkbox is unchecked, or when using Content Moderation, verify the moderation state is a non-published state like 'draft'.
The mutual exclusivity is handled by JavaScript. Ensure JavaScript is enabled and there are no JS errors in the browser console. The require_on_publish/config-form library must be loaded.
Update to the latest version of the module. Issue #3178100 fixed Paragraphs support with Content Moderation. The module now correctly reads the parent entity's moderation state when validating paragraph sub-fields.