getRevisionLogMessage example

// 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;
  }

  /** * Checks block revision related operations. */
  

  protected function assertRevision(array $revision, array $data): void {
    /** @var \Drupal\node\NodeInterface $actual */
    $actual = $this->nodeStorage->loadRevision($revision['vid'])
      ->getTranslation($revision['langcode']);
    $this->assertInstanceOf(NodeInterface::class$actual);
    $this->assertSame($revision['title']$actual->getTitle()sprintf("Title '%s' does not match actual '%s' for revision '%d' langcode '%s'", $revision['title']$actual->getTitle()$revision['vid']$revision['langcode']));
    $this->assertSame($revision['revision_translation_affected']$actual->get('revision_translation_affected')->value, sprintf("revision_translation_affected '%s' does not match actual '%s' for revision '%d' langcode '%s'", $revision['revision_translation_affected']$actual->get('revision_translation_affected')->value, $revision['vid']$revision['langcode']));

    $this->assertSame($data['created']$actual->getRevisionCreationTime()sprintf("Creation time '%s' does not match actual '%s' for revision '%d' langcode '%s'", $data['created']$actual->getRevisionCreationTime()$revision['vid']$revision['langcode']));
    $this->assertSame($data['changed']$actual->getChangedTime()sprintf("Changed time '%s' does not match actual '%s' for revision '%d' langcode '%s'", $data['changed']$actual->getChangedTime()$revision['vid']$revision['langcode']));
    $this->assertSame($data['log']$actual->getRevisionLogMessage()sprintf("Revision log '%s' does not match actual '%s' for revision '%d' langcode '%s'", var_export($data['log'], TRUE)$actual->getRevisionLogMessage()$revision['vid']$revision['langcode']));
  }

  /** * Provides the expected node_field_data table. * * @return array * The expected table rows. */
  protected function expectedNodeFieldDataTable() {
    return [
      0 =>
        [
/** * {@inheritdoc} */
  public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
    parent::preSaveRevision($storage$record);

    if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
      // If we are updating an existing block_content without adding a new       // revision and the user did not supply a revision log, keep the existing       // one.       $record->revision_log = $this->original->getRevisionLogMessage();
    }
  }

  /** * {@inheritdoc} */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = parent::baseFieldDefinitions($entity_type);

    $fields['id']->setLabel(t('Content block ID'))
      
    $storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $targetRevision */
    $targetRevision = $storage->loadRevision($targetRevertRevisionId);

    $this->drupalGet($targetRevision->toUrl('revision-revert-form'));
    $this->submitForm([], 'Revert');

    // Load the new latest revision.     /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $latestRevision */
    $latestRevision = $storage->loadUnchanged($entity->id());
    $this->assertEquals($count + 1, $this->countRevisions($entity->getEntityTypeId()));
    $this->assertEquals('Copy of the revision from <em class="placeholder">Sun, 01/11/2009 - 17:00</em>.', $latestRevision->getRevisionLogMessage());
    $this->assertGreaterThan($revisionCreationTime$latestRevision->getRevisionCreationTime());
    $this->assertEquals($user->id()$latestRevision->getRevisionUserId());
    $this->assertTrue($latestRevision->isDefaultRevision());
  }

  /** * Loads watchdog entries by channel. * * @param string $channel * The logger channel. * * @return string[] * Watchdog entries. */
$context['username'] = $this->renderer->render($username);
    }
    else {
      $linkText = $revision->access('view label') ? $revision->label() : $this->t('- Restricted access -');
    }

    $url = $revision->hasLinkTemplate('revision') ? $revision->toUrl('revision') : NULL;
    $context['revision'] = $url && $url->access()
      ? Link::fromTextAndUrl($linkText$url)->toString()
      : (string) $linkText;
    $context['message'] = $revision instanceof RevisionLogInterface ? [
      '#markup' => $revision->getRevisionLogMessage(),
      '#allowed_tags' => Xss::getHtmlTagList(),
    ] : '';

    return [
      'data' => [
        '#type' => 'inline_template',
        '#template' => isset($context['username'])
          ? '{% trans %} {{ revision }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}'
          : '{% trans %} {{ revision }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}',
        '#context' => $context,
      ],
    ];

  public function testDescriptionRevLogNullValues(): void {
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions')->save();

    // Check entity values are still null after saving; they did not receive     // values from currentUser or some other global context.     $this->assertNull($entity->getRevisionUser());
    $this->assertNull($entity->getRevisionUserId());
    $this->assertNull($entity->getRevisionLogMessage());

    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', 'by Anonymous (not verified)');
  }

  /** * Test description with entity, without revision log, no label access. * * @covers ::getRevisionDescription */
  public function testDescriptionNoRevLogNoLabelAccess(): void {
    

  protected function assertRevision(array $revision, array $data): void {
    /** @var \Drupal\node\NodeInterface $actual */
    $actual = $this->nodeStorage->loadRevision($revision['vid'])
      ->getTranslation($revision['langcode']);
    $this->assertInstanceOf(NodeInterface::class$actual);
    $this->assertSame($revision['title']$actual->getTitle()sprintf("Title '%s' does not match actual '%s' for revision '%d' langcode '%s'", $revision['title']$actual->getTitle()$revision['vid']$revision['langcode']));
    $this->assertSame($revision['revision_translation_affected']$actual->get('revision_translation_affected')->value, sprintf("revision_translation_affected '%s' does not match actual '%s' for revision '%d' langcode '%s'", $revision['revision_translation_affected']$actual->get('revision_translation_affected')->value, $revision['vid']$revision['langcode']));

    $this->assertSame($data['revision_created']$actual->getRevisionCreationTime()sprintf("Creation time '%s' does not match actual '%s' for revision '%d' langcode '%s'", $data['revision_created']$actual->getRevisionCreationTime()$revision['vid']$revision['langcode']));
    $this->assertSame($data['log']$actual->getRevisionLogMessage()sprintf("Revision log '%s' does not match actual '%s' for revision '%d' langcode '%s'", var_export($data['log'], TRUE)$actual->getRevisionLogMessage()$revision['vid']$revision['langcode']));
    if (isset($data['field_text_long_plain'])) {
      $this->assertSame($data['field_text_long_plain']$actual->field_text_long_plain->value, sprintf("field_text_long_plain value '%s' does not match actual '%s' for revision '%d' langcode '%s'", var_export($data['field_text_long_plain'], TRUE)$actual->field_text_long_plain->value, $revision['vid']$revision['langcode']));
    }
    if (isset($data['field_tree'])) {
      $this->assertSame($data['field_tree']$actual->field_tree->value, sprintf("field_tree value '%s' does not match actual '%s' for revision '%d' langcode '%s'", var_export($data['field_tree'], TRUE)$actual->field_tree->value, $revision['vid']$revision['langcode']));
    }

  }

  /** * Provides the expected node_field_data table. * * @return array * The expected table rows. */
$random_timestamp = rand(1e8, 2e8);
    $this->createRevision($entity$user$random_timestamp, 'This is my log message');

    $revision_id = $entity->getRevisionId();
    $revision_ids[] = $revision_id;

    $storage = \Drupal::entityTypeManager()->getStorage('entity_test_mul_revlog');
    $entity = $storage->loadRevision($revision_id);
    $this->assertEquals($random_timestamp$entity->getRevisionCreationTime());
    $this->assertEquals($user->id()$entity->getRevisionUserId());
    $this->assertEquals($user->id()$entity->getRevisionUser()->id());
    $this->assertEquals('This is my log message', $entity->getRevisionLogMessage());

    // Create the third revision.     $random_timestamp = rand(1e8, 2e8);
    $this->createRevision($entity$user$random_timestamp, 'This is my log message');
    $this->assertItemsTableCount(3, $definition);
    $revision_ids[] = $entity->getRevisionId();

    // Create another 3 revisions.     foreach (range(1, 3) as $count) {
      $timestamp = rand(1e8, 2e8);
      $this->createRevision($entity$user$timestamp, 'This is my log message number: ' . $count);
      
$page->pressButton('Save');
    $media_id = $this->container->get('entity_type.manager')
      ->getStorage('media')
      ->getQuery()
      ->accessCheck(FALSE)
      ->execute();
    $media_id = reset($media_id);
    /** @var \Drupal\media\MediaInterface $media */
    $media = $this->container->get('entity_type.manager')
      ->getStorage('media')
      ->loadUnchanged($media_id);
    $this->assertSame($media->getRevisionLogMessage()$revision_log_message);
    $this->assertSame($media->getName()$media_name);

    // Tests media edit form.     $media_type->setNewRevision(FALSE);
    $media_type->save();
    $media_name2 = $this->randomMachineName();
    $this->drupalGet('media/' . $media_id . '/edit');
    $assert_session->checkboxNotChecked('edit-revision');
    $media_name = $this->randomMachineName();
    $page->fillField('name[0][value]', $media_name2);
    $page->pressButton('Save');
    
Home | Imprint | This part of the site doesn't use cookies.