public function ModerationHandler::onPresave in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 src/Entity/Handler/ModerationHandler.php \Drupal\workbench_moderation\Entity\Handler\ModerationHandler::onPresave()
Work to be done before saving en entity.
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
- src/
Entity/ Handler/ ModerationHandler.php, line 33
Class
- ModerationHandler
- Common customizations for most/all entities.
Namespace
Drupal\workbench_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();
}
}