Introducing Scheduled Transitions
Scheduled Transitions is a module allowing you to schedule a specific previously saved revision to move from one state to another. This post provides an introduction to Scheduled Transitions for Drupal 8.
by
Daniel Phin
/ 9 August 2019
Scheduled Transitions is a module allowing you to schedule a specific previously saved revision to move from one state to another. For example an editor may edit a piece of content remaining in a draft state throughout the draft process. When ready, an editor may select the ready revision to be moved from draft to published.
Another more complex use case is with the following workflow Draft -> Needs Review -> Approved -> Published -> Archived. A Content Editor could edit a piece of content until it is in Needs Review status, a Content Moderator will approve the content by setting the state to Approved. The Content Moderator would go to set up a scheduled transition for when the content would move from Approved to Published at some point in the future. If the content is time sensitive, another future scheduled transition could be created to automatically change from Published to Archived.
Scheduled Transitions integrates tightly with Content Moderation and Workflows, inheriting transitions, states, and associated permissions automatically.
This post and accompanying video cover configuration and general usage.
Video
Another shorter version of the video is available without site building aspects, ready to be shared with an editorial team.
Dependencies
Requirements and dependencies are fairly bleeding edge, but will change in the future, as of posting they are:
- Drupal 8.6 or higher
- Dynamic Entity Reference
- PHP 7.1 or higher
- Optionally Drush 9.
Installation
Download and install the module using your favourite method:
composer require drupal/scheduled_transitions
drush pm:enable scheduled_transitions # or
drupal module:install scheduled_transitionsConfiguration
Configure Workflows
If you have not already created a workflow, navigate to Configuration -> Workflows, click Add workflow button.
Create a label, select Content moderation from the Workflow type dropdown.
Set up states and the transitions between in any way you desire, and set which entity type bundles the workflow should apply to.
Configure Scheduled Transitions
Navigate to Configuration » Scheduled Transitions
Under the Enabled types heading, select the entity type bundles to enable Scheduled transitions on. Save the form.
User permissions
Navigate to People » Permissions.
Under Content Moderation heading, enable all workflow transition permissions that apply.Under Scheduled Transitions heading, enable Add scheduled transitions and View scheduled transitions permissions that apply. These permissions apply to individual entities, in addition to these permissions, users must also have access to edit the individual entities. Make sure you grant any permissions needed for users to edit the entities, for example Node's require Edit any content or Edit own content permissions.
General Usage
Moving on to day-to-day functionality of Scheduled Transitions.
Navigate to a pre-existing entity. Though nodes are show in examples below, Scheduled Transitions works with any revisionable entity type. Such as block content, terms, or custom entity types.
You'll find the Scheduled Transitions tab, with a counter in the tab indicating how many transitions are scheduled for the entity and translation being viewed.
Clicking the tab will send you to a listing of all scheduled transitions for an entity.
If the user has permission, an Add Scheduled transitions button will be visible.
Clicking the button presents a modal form. The form displays a list of all revisions for the entity or translation.
Click the radio next to the revision you wish to schedule for state change.
After the radio is selected, the form will reload showing valid workflow transitions from the selected revisions' state.
The user selects which transition is to be executed, along with the date and time the transition should be executed.
Depending on the state of the selected source revision, an additional checkbox may display, prompting me to recreate pending revisions. This feature is useful if users have created more non published revisions after the scheduled revision. It prevents loss of any intermediate non-published work. A diagram is provided below:
Click the schedule button. The modal closes and the scheduled transitions list reloads.
When the time is right, the scheduled transition is executed. You can force schedule transitions to execute by running cron manually. Cron should should be set up to run automatically and regularly, preferably every 5 minutes or so.
The job executes the transitions and deletes itself, removing itself from the transition list. As a result of executing the transition, you'll notice when navigating to the core revisions list for an entity a new revision is created, with a log outlining the state change.
Multilingual
When dealing with entities with multiple translations, you can find that transitions are available for the translation in context, and are separate to other translations. For example revisions in English and German languages of an entity are scheduled independently.
Global List
Scheduled transitions comes with Views integration, on installation a view is pre-installed. You can find the view by navigating to Content » Scheduled Transitions. The view shows all pending scheduled transitions on the site.
For more information, check out the Scheduled Transitions project page or Scheduled Transitions project documentation.
Tagged