Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ModerationHandler.php

function ModerationHandler::onPresave

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal