Introduction
The Need
Our clients and other Drupal site administrators would like to use the Workflow module to schedule transition states in their publishing workflow.
The Problem
Currently, within the Workflow module a node cannot be assigned a scheduled state change upon node creation. A node must be saved first, then edited a second time by the user.
After reading this comment in the Workflow module issue queue: http://drupal.org/node/189572#comment-704334 I decided to try to add a little more automation to the process of creating a node and adding a scheduled state change.
In this Post
You'll learn how to create a publishing workflow for your website, and how to improve the process of scheduling a transition change during node creation.
Let's begin.
Note: This demonstration is build on Drupal 6. The process outlined below may be adapted for Drupal 5 install.
Install and Enable the Necessary Modules
1. Download, install, and enable the necessary third-party modules
o Workflow - http://drupal.org/project/workflow
o Token - http://drupal.org/project/token
o Token actions (part of Token module)
2. Enable Drupal's core Trigger module @ /admin/build/modules


![]()
Set Your Permission Settings
Allow at least one user role a permission to schedule workflow transitions @ /admin/user/permissions#module-workflow

Build Your Workflow
1. Go to /admin/build/workflow/add and add the workflow, giving it the title of "Scheduled Publishing"

2. After saving the workflow, go to /admin/build/workflow/ and click on "Add State"

3. Add the state name "Not Published". Leave Weight set to 0. Save.

4. Repeat steps 2 and 3 to add:
o "Create and Schedule Publishing" giving it a Weight of -1 to make it the first and default state after upon creating the node.
o "Published" leaving weight alone.
You should finish with the workflow sates as illustrated below:

Assign the Workflow to your Content type
In the illustration below, the workflow titled, "Scheduled Publishing" has been assigned to the "Blog" content type.

Build an Advanced Action
1. Go to /admin/settings/actions and scroll down to the form to "Make a new advanced action available"
2. Select the "Redirect to a tokenized URL" option and click "Create".
3. On the "Configure an advanced action" page:
o Give it the description, "Redirect to workflow tab of the node"
o Add the following tokenized URL: node/[nid]/workflow
o Save


Note: It is the use of this tokenized URL which helps automate the scheduled publishing choice after the node has been created. In a moment we are going to assign this action to a Trigger which fires after a new node is created. A redirect will occur to the Workflow tab for the newly created node (based on node id).
Edit the Scheduled Publishing workflow
Return to /admin/build/workflow/ and select the "Edit" link for the "Scheduled Publishing" workflow.

You will be taken to the "Edit workflow Scheduled Publishing" page shown below. On this page, you will choose what transitions each role may be allowed to initiate.
As illustrated below:

Authors may do these transitions -
- (creation) to Create and Schedule Publishing
- (creation) to Not Published
- (creation) to Published
- Create and Schedule Publishing to Not Published
- Create and Schedule Publishing to Published
- Not Published to Published
- Published to Not Published
Blog users may do these transitions -
- (creation) to Create and Schedule Publishing
- (creation) to Not Published
- (creation) to Published
- Create and Schedule Publishing to Not Published
- Create and Schedule Publishing to Published
- Not Published to Published
- Published to Not Published
While on the same page, scroll down to the "Workflow tab permissions" section, and select which roles may have access to the workflow tabs on nodes which have the workflow option. In this case I have selected the author, and the Blog User role.

Assign Actions to Triggers
1. Return to: /admin/build/workflow and click on "Actions" under the "Operations" links for your workflow.
2. You will be taken to the "Triggers" page where you'll set actions to happen when transitions occur.
3. On this page, you'll need to assign a number of actions to a number of triggers. Mainly "Publish" and "Unpublish" post actions to the transitions between your workflow states. On the "Triggers" page, if the "Workflow" tab is not selected, click it now.
Following the list below, add the numbered transactions to the titled triggers.
Trigger: When blog moves from (creation) to Published
1. Publish post
2. Save post
Trigger: When blog moves from (creation) to Not Published
1. Unpublish post
2. Save post
Trigger: When blog moves from (creation) to Create and Schedule Publishing
1. Change workflow state of post to next state
2. Redirect to workflow tab of the node
Trigger: When blog moves from Create and Schedule Publishing to Published
1. Publish post
2. Save post
Trigger: When blog moves from Create and Schedule Publishing to Not Published
1. Unpublish post
2. Save post
Trigger: When blog moves from Not Published to Published
1. Publish post
2. Save post
Trigger: When blog moves from Published to Not Published
1. Unpublish post
2. Save post
Here's How it Works
The following is an example of publishing a node with the blog content type and the "Scheduled Publishing" workflow.
Go to /node/add/blog . You'll notice the following new section on your node add page:

Note: "Create and Schedule Publishing" is selected by default because you set its weight for -1.
Enter sample title and body text and then click "save".
You will be taken to the following page:

Note: In this example, the node id for the new blog post is 125. After saving the new blog post, the system redirected automatically to the following URL: /node/125/workflow .
This action was driven by the advanced action created a the tokenized URL.

Now schedule the content to be published at a future date. The node for this example will be published on Oct 28 2008.
After you hit submit, you will be taken to the blog post.
Note the message at the top of the page shown below which states: "Lorem ipsum dolor sit amet is scheduled for state change to Published on Tue, 10/28/2008 - 12:00am".

Bonus Tip
Check out the Workflow Pending view for a nice summary of pending workflow changes on your site: /workflow/pending

***Want more? I've got a session, Building Complex Application and Publishing Workflows, proposed for the upcoming DrupalCon in Washington, DC. Check out my proposal and vote me up!***
Post new comment