setRevisionLogMessage example

$revision = $storage->createRevision($revision);

    $time = $this->time->getRequestTime();
    if ($revision instanceof EntityChangedInterface) {
      $revision->setChangedTime($time);
    }

    if ($revision instanceof RevisionLogInterface) {
      $originalRevisionTimestamp = $revision->getRevisionCreationTime();
      $date = $this->dateFormatter->format($originalRevisionTimestamp);
      $revision
        ->setRevisionLogMessage($this->t('Copy of the revision from %date.', ['%date' => $date]))
        ->setRevisionCreationTime($time)
        ->setRevisionUserId($this->currentUser()->id());
    }

    return $revision;
  }

  /** * Returns the bundle label of an entity. * * @param \Drupal\Core\Entity\RevisionableInterface $entity * The entity. * * @return string|null * The bundle label. */

  protected function createRevision(EntityInterface $entity, UserInterface $user$timestamp$log_message) {
    $entity->setNewRevision(TRUE);
    $entity->setRevisionCreationTime($timestamp);
    $entity->setRevisionUserId($user->id());
    $entity->setRevisionLogMessage($log_message);
    $entity->save();
  }

}
$entity = $form_state->get('entity');
    /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
    $storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
    $entity = $storage->createRevision($entity$entity->isDefaultRevision());

    $new_state = $form_state->getValue('new_state');

    $entity->set('moderation_state', $new_state);

    if ($entity instanceof RevisionLogInterface) {
      $entity->setRevisionCreationTime($this->time->getRequestTime());
      $entity->setRevisionLogMessage($form_state->getValue('revision_log'));
      $entity->setRevisionUserId($this->currentUser()->id());
    }
    $entity->save();

    $this->messenger()->addStatus($this->t('The moderation state has been updated.'));

    $new_state = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($new_state);
    // The page we're on likely won't be visible if we just set the entity to     // the default state, as we hide that latest-revision tab if there is no     // pending revision. Redirect to the canonical URL instead, since that will     // still exist.


  /** * Test revision log message if supported, and HTML tags are stripped. * * @covers ::getRevisionDescription */
  public function testDescriptionRevisionLogMessage(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions');
    $entity->setRevisionLogMessage('<em>Hello</em> <script>world</script> <strong>123</strong>');
    $entity->save();

    $this->drupalGet($entity->toUrl('version-history'));
    // Script tags are stripped, while admin-safe tags are retained.     $this->assertSession()->elementContains('css', 'table tbody tr:nth-child(1)', '<em>Hello</em> world <strong>123</strong>');
  }

  /** * Test revert operation. * * @covers ::buildRevertRevisionLink */

  }

  /** * {@inheritdoc} */
  protected function prepareEntity() {
    parent::prepareEntity();

    // Hide the current revision log message in UI.     if ($this->showRevisionUi() && !$this->entity->isNew() && $this->entity instanceof RevisionLogInterface) {
      $this->entity->setRevisionLogMessage(NULL);
    }
  }

  /** * Returns the bundle entity of the entity, or NULL if there is none. * * @return \Drupal\Core\Entity\EntityInterface|null * The bundle entity. */
  protected function getBundleEntity() {
    if ($bundle_entity_type = $this->entity->getEntityType()->getBundleEntityType()) {
      


  /** * Tests version history page. */
  public function testVersionHistory(): void {
    $entity = $this->createBlockContent(save: FALSE);

    $entity
      ->setInfo('first revision')
      ->setRevisionCreationTime((new \DateTimeImmutable('1st June 2020 7am'))->getTimestamp())
      ->setRevisionLogMessage('first revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'first author'))
      ->setNewRevision();
    $entity->save();

    $entity
      ->setInfo('second revision')
      ->setRevisionCreationTime((new \DateTimeImmutable('2nd June 2020 8am'))->getTimestamp())
      ->setRevisionLogMessage('second revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'second author'))
      ->setNewRevision();
    $entity->save();

    
$this->assertFalse($entity->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges() found no changes after the entity has been saved.');

    // Update the revision metadata fields and the changed field, which should     // be skipped from checking for changes in     // ContentEntityBase::hasTranslationChanges().     $entity_previous_rev_id = $entity->getRevisionId();
    // Revision metadata field revision_timestamp.     $entity->setRevisionCreationTime(time() + 1);
    // Revision metadata field revision_uid.     $entity->setRevisionUserId($user2->id());
    // Revision metadata field revision_log.     $entity->setRevisionLogMessage('test');
    // Revision metadata field revision_translation_affected.     $entity->setRevisionTranslationAffected(TRUE);
    // Changed field.     $entity->setChangedTime(time() + 1);

    // Check that the revision metadata fields and the changed field have been     // skipped when comparing same revisions.     $this->assertFalse($entity->hasTranslationChanges(), 'ContentEntityBase::hasTranslationChanges() found no changes when comparing different revisions.');

    // Check that the revision metadata fields and the changed field have been     // skipped when comparing same revisions with enforced new revision to be
$blocks = [];
    $logs = [];

    // Get original block.     $blocks[] = $block->getRevisionId();
    $logs[] = '';

    // Create three revisions.     $revision_count = 3;
    for ($i = 0; $i < $revision_count$i++) {
      $block->setNewRevision(TRUE);
      $block->setRevisionLogMessage($this->randomMachineName(32));
      $block->setRevisionUser($this->adminUser);
      $block->setRevisionCreationTime(REQUEST_TIME);
      $logs[] = $block->getRevisionLogMessage();
      $block->save();
      $blocks[] = $block->getRevisionId();
    }

    $this->blocks = $blocks;
    $this->revisionLogs = $logs;
  }

  
Home | Imprint | This part of the site doesn't use cookies.