Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

Example How to get last content moderation state in drupal 8

// Check if we are viewing the default revision.
if ($entity->isDefaultRevision() == TRUE) {

    $revision_ids = \Drupal::entityTypeManager()->getStorage('node')->revisionIds($entity);
    //$current_revision_id = $node->getRevisionId();

    // Check if the last item in the revisions is the loaded one.
    $last_revision_id = end($revision_ids);

    if ($entity->getRevisionId() != $last_revision_id) {
        // Load the revision.
        $last_revision = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($last_revision_id);
        // Get the revisions moderation state.
        $last_revision_state = $last_revision->get('moderation_state')->getString();


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon