Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Drupal 10 Development Cookbook

You're reading from   Drupal 10 Development Cookbook Practical recipes to harness the power of Drupal for building digital experiences and dynamic websites

Arrow left icon
Product type Paperback
Published in Feb 2023
Publisher Packt
ISBN-13 9781803234960
Length 442 pages
Edition 3rd Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Matt Glaman Matt Glaman
Author Profile Icon Matt Glaman
Matt Glaman
Kevin Quillen Kevin Quillen
Author Profile Icon Kevin Quillen
Kevin Quillen
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Chapter 1: Up and Running with Drupal 2. Chapter 2: Content Building Experience FREE CHAPTER 3. Chapter 3: Displaying Content through Views 4. Chapter 4: Extending Drupal with Custom Code 5. Chapter 5: Creating Custom Pages 6. Chapter 6: Accessing and Working with Entities 7. Chapter 7: Creating Forms with the Form API 8. Chapter 8: Plug and Play with Plugins 9. Chapter 9: Creating Custom Entity Types 10. Chapter 10: Theming and Frontend Development 11. Chapter 11: Multilingual and Internationalization 12. Chapter 12: Building APIs with Drupal 13. Chapter 13: Writing Automated Tests in Drupal 14. Chapter 14: Migrating External Data into Drupal 15. Index 16. Other Books You May Enjoy

Creating an editorial workflow with content moderation

Many organizations have an editorial workflow that must be followed before content can be published on the website. The Content Moderation module allows content created in Drupal to go through an editorial process before it is published. In this recipe, we will create a content moderation workflow that puts content in a draft state and then reviews, approves, and publishes it. The content remains in a draft state and is hidden from site visitors until it is published.

Getting ready

In this recipe, we will be using the standard installation, which provides the Article content type. Any content type will suffice.

How to do it…

  1. Begin by installing the Content Moderation module and its dependent module, Workflows:
    php vendor/bin/drush en content_moderation –yes
  2. Visit Configuration and then Workflows. This page lists all configured content moderation workflows. Click Add workflow to create a new workflow.
  3. In the Label field, give it a label of Approval workflow and select Content moderation for Workflow type.
  4. The workflow has two default states of Draft and Published. We need to add Review and Approval states. For each of our new states, click the Add a new state link. Fill in the State label and press Save. Leave the Published and Default revision checkboxes unchecked. Those should only be used for a published state.
  5. Rearrange the states’ ordering so that it is Draft, Review, Approval, Published. Press Save at the bottom of the form so that our ordering is saved.
  6. Next, we need to create a transition to move a Draft to Review. Click Add a new transition. Set the Transition label to Ready for review. Select Draft as a From state. Then, select Review as the To state and press Save.
  7. Now, we will create the Review to Approval transition. Click Add a new transition. Set the Transition label to Needs approval. Select Review as a From state. Then, select Approval as the To state and press Save.
  8. We must edit the default Publish transition. Uncheck Draft from the From checkboxes and select Approval.
  9. Finally, we must assign this workflow to content entities. Under This workflow applies to, look for Content types. Press Select and a dialog will open. Check Article, then press Save in the dialog.
  10. Press Save at the bottom of the form. Our content moderation workflow is now complete!

How it works…

Without Content Moderation, publishable content entities only have two states: unpublished or published. There also are no permissions to control who can make an unpublished piece of content published or vice versa. Content Moderation solves this problem.

The Workflows module provides an API for defining states and transitions. It is up to modules such as Content Moderation to provide Workflow Type plugins to bring meaningful functionality. The Content Moderation module integrates with the revision capabilities of Drupal content entities.

When editing a content entity that uses Content Moderation, there will be a Moderation State field. This field contains the states that a piece of content can transition to, based on the current user’s permissions.

See also

You have been reading a chapter from
Drupal 10 Development Cookbook - Third Edition
Published in: Feb 2023
Publisher: Packt
ISBN-13: 9781803234960
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image