EntityOperations::entityPresave

public EntityOperations::entityPresave(EntityInterface $entity)

Acts on an entity and set published status based on the moderation state.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity being saved.

File

core/modules/content_moderation/src/EntityOperations.php, line 85

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\content_moderation

Code

public function entityPresave(EntityInterface $entity) {
  if (!$this->moderationInfo->isModeratedEntity($entity)) {
    return;
  }
  if ($entity->moderation_state->target_id) {
    $moderation_state = $this->entityTypeManager
      ->getStorage('moderation_state')
      ->load($entity->moderation_state->target_id);
    $published_state = $moderation_state->isPublishedState();

    // This entity is default if it is new, the default revision, or the
    // default revision is not published.
    $update_default_revision = $entity->isNew()
      || $moderation_state->isDefaultRevisionState()
      || !$this->isDefaultRevisionPublished($entity);

    // Fire per-entity-type logic for handling the save process.
    $this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->onPresave($entity, $update_default_revision, $published_state);
  }
}
doc_Drupal
2016-10-29 09:07:16
Comments
Leave a Comment

Please login to continue.