Get the moderation state of entity or node programmatically in drupal 8

Worfklows are a powerful tool to add events and states to your entities. Here's how to get the current state programmatically:

// Make sure the entity is an object
$entity->get('moderation_state')->getString();

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!