You are here

protected function ModerationStateValidator::isFirstTimeModeration in Workbench Moderation 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Validation/Constraint/ModerationStateValidator.php \Drupal\workbench_moderation\Plugin\Validation\Constraint\ModerationStateValidator::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\EntityInterface $entity: The entity we may be moderating.

Return value

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

File

src/Plugin/Validation/Constraint/ModerationStateValidator.php, line 124

Class

ModerationStateValidator
Class for validating moderations states.

Namespace

Drupal\workbench_moderation\Plugin\Validation\Constraint

Code

protected function isFirstTimeModeration(EntityInterface $entity) {
  $original_entity = $this->moderationInformation
    ->getLatestRevision($entity
    ->getEntityTypeId(), $entity
    ->id());
  $original_id = $original_entity->moderation_state->target_id;
  return !($entity->moderation_state->target_id && $original_entity && $original_id);
}