How to Schedule a Publication in Drupal? Scheduler Module
When creating content for a website, it is sometimes necessary to plan its publication later down the line. However, taking care of it manually can be both time-consuming and inconvenient. This is when Scheduler comes in handy – a Drupal module that will help you automate this process. Using it will allow us, among other things, to schedule the publication of content for a specific date and time.
Scheduler module - dates
The module was released on 23 July 2006, and its latest update was pushed on 19 July 2021. Scheduler has versions for Drupal 7 and 8. What is more, the latest update is compatible with Drupal 9 as well.
Module popularity
The module is currently used on more than 85 thousand websites. About 44 thousand of them are running Drupal 7, and more than 37 thousand are on Drupal 8.
Source: Drupal.org
Module developers
Scheduler was originally published by Eric Schaefer. However, the list of people working on its development to date is very long and impossible to establish – we don’t know all the users who contributed to its development.
Drupal Scheduler module – what does it do?
As I pointed out in the introduction, the module is used to plan content publication in advance. It also offers you a way to plan unpublishing. If needed – for example, in the case of events, where news will be made obsolete after the end, you can task the module with publishing your content and schedule its removal from your website at a specific day and time.
Scheduler provides three new permissions, allowing only the selected roles to have access to scheduled publishing. The list of possibilities also includes the so-called Lightweight cron, the configuration of which optimizes resource consumption. Lightweight cron is the developers' solution to make the cron responsible for publishing and removing content available to be run separately, without the need to initiate all other tasks, as is usually the case in Drupal.
Unboxing
Installation is standard. I recommend using Composer.
composer require drupal/scheduler
Permissions
Go to
/admin/people/permissions#module-scheduler
– there, you will find a list of permissions that the module provides:
Administer scheduler
This setting enables you to configure the Scheduler module, available at
/admin/config/content/scheduler
(see the next section for the description of all the features).
Scheduler content publication
Granting this permission allows a role to set scheduled publication, as well as to plan unpublishing.
View scheduled content list
Scheduler provides a view, which is available at
/admin/content/scheduled
Granting this permission allows you to access this view.
Settings
Go to
/admin/config/content/scheduler
to find all the global settings for the module. What is more, Scheduler can be configured per content type. Below, you can find a break down the global options.
Allow users to enter only a date and provide a default time
Allows users who have permission to configure scheduled content publishing to specify only the publication date. When this option is selected, the time will be predefined and configurable in the Default time field.
Hide the second
Checking this option disables the ability to set seconds when scheduling content publishing.
Lightweight cron
As I pointed out earlier, by default, Drupal runs all cron jobs every once in a while. Checking which content needs to be published and unpublished relies on a cron job, which should be run every 1-5 minutes. Configuring Drupal to run all cron jobs every minute is hardly a very good idea, considering its performance, which is why the developers enabled the users to run a single cron job at a suitable interval. To do this, you need to add a new cron job run at a given time. Here is an example of a cron job that is run every minute:
* * * * * wget -q -O /dev/null "https://tesd9.lndo.site/scheduler/cron/{access-key}
Go to
/admin/config/content/scheduler/cron
to find the lightweight cron settings. There, you can enable logging of cron job activation and completion, change access-key and run cron manually.
Content type
I’ll illustrate this option with the default content type - Article - available in Drupal default profile. Go to
/admin/structure/types/manage/{content-type-machine-name}
There, you will notice a new Scheduler tab. This is where you’ll find all the module's configuration options, which you can set for each entity.
Enable scheduled publishing/unpublishing for this content type
Enables or disables the ability to set scheduled publication and/or unpublishing.
Change content creation time to match the scheduled publish time
Changes the date in the creation time field to the date selected as the planned publication date.
Require scheduled publishing/unpublishing
Checking this option makes setting scheduled publication and/or unpublishing required.
Create a new revision on publishing/unpublishing
Creates a new revision during scheduled publication and/or unpublishing.
Action to be taken for publication dates in the past
This setting enables you to specify what will happen when the editor selects a publication date earlier than the current date. You can choose one of three options here:
- Display an error message about choosing a date earlier than the current one – in this case, the content won’t be published.
- Publish content immediately after saving.
- Schedule your content to be published on the next cron job run.
Display scheduling options as
Changes the way Scheduler module options are displayed when creating and editing content. There are two options to choose from – Vertical tab and Separate fieldset.
Vertical tab
Separate fieldset
Expand fieldset or vertical tab
Allows you to specify whether the field provided by the Scheduler should be expanded when creating and editing content.
Show message
Checking this option displays information about planned publication and unpublishing after saving the content.
Module usage
Let's assume that our article needs to go live on 1 September 2021 at 9:30 a.m. and won't have to be unpublished.
When writing the article, choose Publish on and set it to 01.09.2021 at 9:30 a.m., and then leave Unpublish on empty. In this case, the Require scheduled unpublishing option must be disabled for the Article entity.
Now imagine that our article needs to go live on 1 September 2021 at 9:30 a.m. and has to be unpublished a week later at the same time.
Let's start with doing the same thing as we did in the previous example, but this time also set Unpublish on to 08.09.2021 at 9:30 a.m.
You may be also interested in: How to Make Content Editing Easier in Drupal - Review of the Simplify Module
Integrations
Scheduler offers integrations with several Drupal modules.
- If you’re using the Content Moderation module, you must enable the Content Moderation Integration sub-module.
- Scheduler provides additional conditions, actions, and events for the Rules module.
- It is also integrated with the automatic generation of test content provided by the Devel Generate module. Scheduler can automatically add the planned publication and unpublishing dates.
- It also creates new tokens for the Token module, containing the planned publication and unpublishing dates.
The future of the module
The developers responsible for the Scheduler have announced that they are working on releasing version 2.0 of the module, supporting entities other than nodes, for example, Media, Commerce Products, and more. They also announced that events triggered by the Scheduler module and its integration with the Rules module will from now on be triggered after an entity is saved, rather than before, as was the case until now. The development progress can be followed on the module page.
Drupal Scheduler module – summary
Scheduler is a tool that greatly facilitates the scheduling publication of content on your website. Using it allows you to automate the process and makes it possible to do all the steps required to publish content at any time – thus making sure that you won't have to worry about it when the time comes. At Droptica, we also use Scheduler to schedule publications in advance. This module is extremely popular among Drupal users, and as such, it is constantly developed – with version 2.0 in the works right now. Our team of Drupal developers recommends using the Scheduler module to schedule publications in advance or to publish content for a specific time.