function ModerationHandler::onPresave
Operates on moderated content entities preSave().
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to modify.
bool $default_revision: Whether the new revision should be made the default revision.
bool $published_state: Whether the state being transitioned to is a published state or not.
Overrides ModerationHandlerInterface::onPresave
File
- 
              core/modules/ content_moderation/ src/ Entity/ Handler/ ModerationHandler.php, line 42 
Class
- ModerationHandler
- Common customizations for most/all entities.
Namespace
Drupal\content_moderation\Entity\HandlerCode
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.
