You are here

protected function ModerationStateValidator::isFirstTimeModeration in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 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:

Return value

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

1 call to ModerationStateValidator::isFirstTimeModeration()
ModerationStateValidator::validate in src/Plugin/Validation/Constraint/ModerationStateValidator.php
Checks if the passed value is valid.

File

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

Class

ModerationStateValidator

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