function ModerationInformation::isFirstTimeModeration

Same name in other branches
  1. 9 core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::isFirstTimeModeration()
  2. 10 core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::isFirstTimeModeration()
  3. 11.x core/modules/content_moderation/src/ModerationInformation.php \Drupal\content_moderation\ModerationInformation::isFirstTimeModeration()

Determines if this entity is being moderated for the first time.

If the previous version of the entity has no moderation state, we assume that means it predates the presence of moderation states.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity being moderated.

Return value

bool TRUE if this is the entity's first time being moderated, FALSE otherwise.

1 call to ModerationInformation::isFirstTimeModeration()
ModerationInformation::getOriginalState in core/modules/content_moderation/src/ModerationInformation.php
Gets the original or initial state of the given entity.

File

core/modules/content_moderation/src/ModerationInformation.php, line 269

Class

ModerationInformation
General service for moderation-related questions about Entity API.

Namespace

Drupal\content_moderation

Code

protected function isFirstTimeModeration(ContentEntityInterface $entity) {
    $storage = $this->entityTypeManager
        ->getStorage($entity->getEntityTypeId());
    $original_entity = $storage->loadRevision($storage->getLatestRevisionId($entity->id()));
    if ($original_entity) {
        $original_id = $original_entity->moderation_state;
    }
    return !($entity->moderation_state && $original_entity && $original_id);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.