n How to get last content moderation state in drupal 8 | CodimTh

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
Category:

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();
    }
}

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook