Although the ability to publish and unpublish exists in the Scheduler module, it works with any content entity.

This module allows you to schedule the publishing and unpublishing of any content entity type (node, term, or even path_alias (theoretically), plus any custom entity you might create - as long as it has a "status" property and the other fields listed below).

In addition it does this using the generic Event Scheduler module that uses Symfony events rather than hooks.

How to use

Assuming you have this module installed and enabled all you have to do is add either or both of the following fields to the entity or bundle:

* `field_scheduled_start`
* `field_scheduled_end`

These must be date fields storing in the `Y-m-d\TH:i:s` format. They can be just for the "date" part, in which case it will be assumed to be the start of the day for the publish, and the end of the day for the unpublish.

The timezone used will be the one belonging to the creator of the entity.

If the publish date/time is already past, the entity will be published immediately. Similarly for the unpublish date/time.

Events

You don't need to do any coding for this to work but for developers there are two events issued once the action has been performed:

  • EntityPublishedEvent when an entity has been successfully published.
  • EntityUnpublishedEvent when an entity has been successfully unpublished.

If you want to carry out other actions you will normally intercept those two in an event subscriber. Those two events are both delayed events and will be launched after the rest of the page has been built and sent to the browser.

If an entity is deleted while events are pending, those events are automatically removed.

And that's all there is to it.

Important note

No module of this type can guarantee publishing at an exact time because scheduled events depend on when "cron" is run. The more frequently it's run, the closer to the correct time the publish/unpublish will be.

Project information

Releases