function ModerationHandler::onPresave

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php \Drupal\content_moderation\Entity\Handler\ModerationHandler::onPresave()
  2. 10 core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php \Drupal\content_moderation\Entity\Handler\ModerationHandler::onPresave()
  3. 11.x core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php \Drupal\content_moderation\Entity\Handler\ModerationHandler::onPresave()

Overrides ModerationHandlerInterface::onPresave

File

core/modules/content_moderation/src/Entity/Handler/ModerationHandler.php, line 34

Class

ModerationHandler
Common customizations for most/all entities.

Namespace

Drupal\content_moderation\Entity\Handler

Code

public function onPresave(ContentEntityInterface $entity, $default_revision, $published_state) {
    // When entities are syncing, content moderation should not force a new
    // revision to be created and should not update the default status of a
    // revision. This is useful if changes are being made to entities or
    // revisions which are not part of editorial updates triggered by normal
    // content changes.
    if (!$entity->isSyncing()) {
        $entity->setNewRevision(TRUE);
        $entity->isDefaultRevision($default_revision);
    }
    // Update publishing status if it can be updated and if it needs updating.
    if ($entity instanceof EntityPublishedInterface && $entity->isPublished() !== $published_state) {
        $published_state ? $entity->setPublished() : $entity->setUnpublished();
    }
}

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