From the course: Drupal 9 Essential Training: 4 Users and Themes

Creating content workflows - Drupal Tutorial

From the course: Drupal 9 Essential Training: 4 Users and Themes

Start my 1-month free trial

Creating content workflows

- [Instructor] One of the things I get asked a lot when I do public training is can we set up workflows where a content editor can create a node but someone needs to come along and approve the node and we want to keep those roles separate from say even an administrator? Well, the answer is absolutely. Head over to Extend. And scroll down to the bottom of Core and you'll see Workflows. Now, workflows requires content moderation. So we'll need to turn that one on as well. Put a check mark in Workflows. Scroll back up and find content moderation and put a check mark in there. What this is going to do is exactly what it sounds like. Create workflows for content moderation. Scroll down to the bottom and click Install. Two modules have been enabled. Go to Configuration, Workflow and Workflows. And there's one here set up by default and we'll just use this one for now. Go ahead and click Edit. And there are three parts to this. The states, so what state is the node in? Draft, published and archived in this case. And of course, you can have as many states as you want. A state might be needs approval, something like that. For every set of states, you need transitions between those states. And so you need to think this through and plan it from Draft, Published to Draft, Draft and Published to Published, Published to Archived, Archived to Draft, Archived to Published. And there you go. Each state needs the equivalent transitions. Finally, we get to choose what this workflow applies to and you'll notice block types, media types and content types and that's really terrific. Go ahead and click on Select for content types. And let's just choose basic page. That's a good example. We're not really using that yet, so we'll be able to test that out. Click Save. And you'll see that the content type is including basic page. Default moderation state then is draft. So when I click new basic page, it's going to be saved automatically as a draft. All right, go ahead and click Save. Now, you'll remember from our site building workflow, this is under permissions and any time you add a module like this, you need to manage your permissions. Now, while this is a pretty good overview of the site building workflow, permissions is the kind of thing you revisit a lot as you're building your site. So head back over to People and Permissions, and just below the top, you're going to find a new section called Content Moderation. All right, what workflows can the content editor use? Well, obviously, we're going to let them create a new draft. We'll let them restore to draft. We'll let them view unpublished content. And we'll let them view the latest version. But what we won't do is let them archive nodes and we won't let them publish nodes or restore nodes from draft to published. So this is going to limit the content editor's ability, specifically in the basic page content type. All right, scroll down and click Save. I'm going to head back over and log back in as content editor. And click on Content. Let's filter by basic page. I think we've got one. There it is. You can see that I can edit and I can delete. But if I click About Drupalville and I click Edit, I can change to draft but I can't change it back to archived. That makes sense. That node has already been proofed and published and ready to go. You'll also notice that there's a latest version tab here. Let's go in and make a change. And click Save. Here's my change but it's in draft mode. If I log out, I can still see the version of my About page before the changes were made because they haven't been approved by an administrator or a publisher. And so a content editor who is allowed to edit a node but not publish it, their changes don't go live on the site while they are editing the node. If I come back over when I'm logged in as admiinistrator and go to About Drupalville, again you'll see latest version and because I'm an administrator, I can change it to published. And now that latest version tab is gone. I have a new version of the node, and my changes are live. The workflow module is incredibly helpful. Even if you don't need sophisticated workflows, being able to edit a node without your changes going live immediately and having someone just say proof them for you is really helpful. And that's the workflow module. There's lots of tutorials out there on the internet and we have more at OSTraining. I'd encourage you to take a look at some of those to see some of the more advanced workflows that you can create.

Contents