content_moderation_test_resave.module

Same filename and directory in other branches
  1. 9 core/modules/content_moderation/tests/modules/content_moderation_test_resave/content_moderation_test_resave.module
  2. 10 core/modules/content_moderation/tests/modules/content_moderation_test_resave/content_moderation_test_resave.module

Contains hook implementations for the Content moderation test re-save module.

File

core/modules/content_moderation/tests/modules/content_moderation_test_resave/content_moderation_test_resave.module

View source
<?php


/**
 * @file
 * Contains hook implementations for the Content moderation test re-save module.
 */
use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_entity_insert().
 */
function content_moderation_test_resave_entity_insert(EntityInterface $entity) {
    
    /** @var \Drupal\content_moderation\ModerationInformationInterface $content_moderation */
    $content_moderation = \Drupal::service('content_moderation.moderation_information');
    if ($content_moderation->isModeratedEntity($entity)) {
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
        // Saving the passed entity object would populate its loaded revision ID,
        // which we want to avoid. Thus, save a clone of the original object.
        $cloned_entity = clone $entity;
        // Set the entity's syncing status, as we do not want Content Moderation to
        // create new revisions for the re-saving. Without this call Content
        // Moderation would end up creating two separate content moderation state
        // entities: one for the re-save revision and one for the initial revision.
        $cloned_entity->setSyncing(TRUE)
            ->save();
        // Record the fact that a re-save happened.
        \Drupal::state()->set('content_moderation_test_resave', TRUE);
    }
}

Functions

Title Deprecated Summary
content_moderation_test_resave_entity_insert Implements hook_entity_insert().

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