Scheduler Content Moderation Integration
Provides integration between Scheduler module and Drupal's Content Moderation workflow system, enabling scheduled moderation state transitions.
scheduler_content_moderation_integration
Install
composer require 'drupal/scheduler_content_moderation_integration:^3.0'
composer require 'drupal/scheduler_content_moderation_integration:^2.0'
Overview
Scheduler Content Moderation Integration (SCMI) is a sub-module that bridges the Scheduler module with Drupal's core Content Moderation system. When you need to schedule content to be published or unpublished while using moderation workflows, this module is essential.
The module adds two new fields to moderated entities: "Publish state" and "Unpublish state". These fields allow content editors to specify which moderation state the content should transition to when the scheduled publish or unpublish date/time is reached. For example, in a typical "Draft-Published-Archived" workflow, an editor can create content in Draft state and schedule it to automatically transition to Published state at a future date.
When the scheduled time arrives and cron runs, the module handles the moderation state transition rather than the standard publish/unpublish action. This ensures workflow rules, permissions, and transition validations are respected during scheduled operations.
Features
- Adds 'Publish state' and 'Unpublish state' fields to all entity types that support both Scheduler and Content Moderation
- Validates scheduled transitions against the workflow's allowed transitions to prevent invalid state changes
- Validates user permissions for scheduled transitions, ensuring users can only schedule transitions they have access to
- Dynamically generates state options based on valid transitions from the entity's current moderation state
- Supports multiple entity types including nodes, media, and any other entity type with Scheduler plugins
- Hides scheduling fields when no valid moderation transitions are available for the current user
- Handles immediate publishing through Scheduler's publish-immediately feature with proper moderation state handling
- Integrates seamlessly with existing Content Moderation workflows without requiring additional configuration
Use Cases
Schedule Draft Content for Future Publication
An editor creates a news article and saves it as Draft. They want it to go live next Monday at 9 AM. Using the Scheduling Options, they set the 'Publish on' date/time to Monday 9 AM and select 'Published' as the 'Publish state'. When cron runs after that time, the content automatically transitions from Draft to Published.
Schedule Auto-Archival of Time-Sensitive Content
A promotional page needs to be published for one week only. The editor sets up both scheduled publishing and unpublishing: 'Publish on' is set to the campaign start date with 'Publish state' set to Published, and 'Unpublish on' is set to the campaign end date with 'Unpublish state' set to Archived. The content automatically goes live and is archived without manual intervention.
Prepare Content Updates in Advance
An existing Published article needs updates that should go live at a specific time. The editor edits the content, makes changes, and sets the current state to Draft (creating a new draft revision). They schedule the Draft to transition to Published at the desired time. The original published version remains visible until the scheduled time when the new revision becomes the published version.
Multi-Stage Publishing Workflow
In an organization with an editorial workflow (Draft -> Review -> Published -> Archived), content needs approval before scheduling. Editors create content in Draft, move it to Review for approval. Once approved, they can schedule the transition to Published. The module validates that the transition from Review to Published is valid in the workflow.
Media Asset Scheduling
Media items (images, videos, audio) that are part of a moderation workflow can also be scheduled. For example, a promotional video can be scheduled to become available (Published state) at the campaign launch and automatically archived afterward.
Tips
- The module automatically hides the Scheduler date fields when no valid state transitions are available, preventing user confusion
- Use the 'use [workflow] transition [transition]' permissions to control which users can schedule specific transitions
- Both publish and unpublish can be scheduled together - the unpublish_state options are calculated based on what states are reachable from the selected publish_state
- The module works with any custom Content Moderation workflow - you're not limited to the default 'editorial' workflow
- For testing, you can trigger scheduled transitions immediately using 'drush scheduler:cron' instead of waiting for system cron
Technical Details
Hooks 9
hook_scheduler_publish_process
Processes scheduled publishing for moderated entities. Instead of the standard Scheduler publish action, this hook transitions the entity to the scheduled publish_state. Returns 1 if processed, -1 on error, or 0 to let Scheduler handle it normally.
hook_scheduler_unpublish_process
Processes scheduled unpublishing for moderated entities. Transitions the entity to the scheduled unpublish_state (e.g., 'archived' or 'draft'). Returns 1 if processed, -1 on error, or 0 to let Scheduler handle it normally.
hook_scheduler_hide_publish_date
Hides the Scheduler publish_on date field when there are no valid moderation transitions available for publishing. This prevents users from setting a publish date when they cannot transition to any published state.
hook_scheduler_hide_unpublish_date
Hides the Scheduler unpublish_on date field when there are no valid moderation transitions available for unpublishing. This prevents users from setting an unpublish date when they cannot transition to any unpublished state.
hook_entity_base_field_info
Defines the publish_state and unpublish_state base fields for all entity types that are both supported by Scheduler plugins and can be moderated. These fields store the target moderation state for scheduled transitions.
hook_entity_access
Denies update access when a user does not have permission for scheduled transitions. Validates that the user can perform the transitions specified in publish_state and unpublish_state fields.
hook_form_alter
Attaches publish_state and unpublish_state fields to the Scheduler settings group in entity forms. Also hides these fields when scheduled publishing/unpublishing is not enabled for the entity type.
hook_entity_presave
Prevents published moderation states from being saved when the entity's published status is set to false by Scheduler. This ensures consistency between the moderation state and the entity's published status.
hook_modules_installed
When a new module with a Scheduler plugin is installed, automatically adds the publish_state and unpublish_state fields to the corresponding entity type's database tables.
Troubleshooting 6
Verify that: 1) The entity type is enabled for scheduling in its Scheduler settings, 2) The entity type is added to a Content Moderation workflow, 3) The current user has permission to use at least one workflow transition. If the workflow has no valid transitions for the user, the fields are intentionally hidden.
Ensure cron is running properly. Check that the transition from the entity's current state to the scheduled state is valid in your workflow configuration. Review the dblog for any errors during the scheduled processing.
The selected publish_state cannot be reached from the entity's current moderation state. Check your workflow configuration to ensure a transition exists between the current state and the target state.
The current user lacks the 'use [workflow] transition [transition_id]' permission. Grant the appropriate transition permissions to the user's role.
This occurs when entity types are removed from moderation. Run the update hook by visiting update.php or run 'drush updb'. Alternatively, run: drush ev '_scheduler_content_moderation_integration_remove_fields()'
This happens when no valid transitions exist from the entity's current state. Check that your workflow has transitions defined from the current state to published/unpublished states, and that the user has permission for those transitions.
Security Notes 3
- The module validates transition permissions at save time - users cannot schedule transitions they don't have permission to perform
- Access checks are also performed when loading entities with scheduled transitions, preventing privilege escalation
- The module respects existing Content Moderation access controls and does not bypass any workflow restrictions