getRevisionCreationTime example


  protected function getRevisionDescription(RevisionableInterface $revision): array {
    $context = [];
    if ($revision instanceof RevisionLogInterface) {
      // Use revision link to link to revisions that are not active.       ['type' => $dateFormatType, 'format' => $dateFormatFormat] = $this->getRevisionDescriptionDateFormat($revision);
      $linkText = $this->dateFormatter->format($revision->getRevisionCreationTime()$dateFormatType$dateFormatFormat);

      // @todo Simplify this when https://www.drupal.org/node/2334319 lands.       $username = [
        '#theme' => 'username',
        '#account' => $revision->getRevisionUser(),
      ];
      $context['username'] = $this->renderer->render($username);
    }
    else {
      $linkText = $revision->access('view label') ? $revision->label() : $this->t('- Restricted access -');
    }

    
$node = Node::load(1);
    $this->assertSame('1', $node->id(), 'Node 1 loaded.');
    $this->assertSame('und', $node->langcode->value);
    $this->assertSame('body test rev 3', $node->body->value);
    $this->assertSame('teaser test rev 3', $node->body->summary);
    $this->assertSame('filtered_html', $node->body->format);
    $this->assertSame('story', $node->getType(), 'Node has the correct bundle.');
    $this->assertSame('Test title rev 3', $node->getTitle(), 'Node has the correct title.');
    $this->assertSame('1390095702', $node->getCreatedTime(), 'Node has the correct created time.');
    $this->assertFalse($node->isSticky());
    $this->assertSame('1', $node->getOwnerId());
    $this->assertSame('1420861423', $node->getRevisionCreationTime());

    /** @var \Drupal\node\NodeInterface $node_revision */
    $node_revision = \Drupal::entityTypeManager()->getStorage('node')->loadRevision(2001);
    $this->assertSame('Test title rev 3', $node_revision->getTitle());
    $this->assertSame('2', $node_revision->getRevisionUser()->id(), 'Node revision has the correct user');
    $this->assertSame('1', $node_revision->id(), 'Node 1 loaded.');
    $this->assertSame('2001', $node_revision->getRevisionId(), 'Node 1 revision 2001 loaded.');
    // This is empty on the first revision.     $this->assertSame('modified rev 3', $node_revision->revision_log->value);
    $this->assertSame('This is a shared text field', $node->field_test->value);
    $this->assertSame('filtered_html', $node->field_test->format);
    
$another_user = $this->drupalCreateUser($this->permissions);
    $this->grantUserPermissionToCreateContentOfType($another_user, 'moderated_content');
    $this->drupalLogin($another_user);
    $this->drupalGet(sprintf('node/%d/latest', $node->id()));
    $this->submitForm(['new_state' => 'published'], 'Apply');

    $this->drupalGet(sprintf('node/%d/revisions', $node->id()));
    $this->assertSession()->pageTextContains('by ' . $another_user->getAccountName());

    // Verify the revision creation time has been updated.     $node = $node->load($node->id());
    $this->assertGreaterThan(12345, $node->getRevisionCreationTime());
  }

  /** * Tests translated and moderated nodes. */
  public function testContentTranslationNodeForm() {
    $this->drupalLogin($this->rootUser);

    // Add French language.     $edit = [
      'predefined_langcode' => 'fr',
    ];
'format' => \DateTime::RFC3339,
        ],
      ],
      'default_langcode' => [
        [
          'value' => TRUE,
        ],
      ],
      'parent' => [],
      'revision_created' => [
        [
          'value' => (new \DateTime())->setTimestamp((int) $this->entity->getRevisionCreationTime())
            ->setTimezone(new \DateTimeZone('UTC'))
            ->format(\DateTime::RFC3339),
          'format' => \DateTime::RFC3339,
        ],
      ],
      'revision_user' => [],
      'revision_log_message' => [],
      'revision_translation_affected' => [
        [
          'value' => TRUE,
        ],
      ],

  public function revisionPageTitle(NodeInterface $node_revision) {
    return $this->t('Revision of %title from %date', [
      '%title' => $node_revision->label(),
      '%date' => $this->dateFormatter->format($node_revision->getRevisionCreationTime()),
    ]);
  }

  /** * Generates an overview table of older revisions of a node. * * @param \Drupal\node\NodeInterface $node * A node object. * * @return array * An array as expected by \Drupal\Core\Render\RendererInterface::render(). */
// 200 for well-formed request.     $response = $this->request('PATCH', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response);
    $this->assertFalse($response->hasHeader('X-Drupal-Cache'));
    // Assert that the entity was indeed updated, and that the response body     // contains the serialized updated entity.     $updated_entity = $this->entityLoadUnchanged($this->entity->id());
    $this->assertSame(static::$newRevisionsShouldBeAutomatic$prior_revision_id < (int) $updated_entity->getRevisionId());
    if ($this->entity instanceof RevisionLogInterface) {
      if (static::$newRevisionsShouldBeAutomatic) {
        $this->assertNotSame((int) $this->entity->getRevisionCreationTime()(int) $updated_entity->getRevisionCreationTime());
      }
      else {
        $this->assertSame((int) $this->entity->getRevisionCreationTime()(int) $updated_entity->getRevisionCreationTime());
      }
    }
    $updated_entity_document = $this->normalize($updated_entity$url);
    $this->assertSame($updated_entity_document, Json::decode((string) $response->getBody()));
    $prior_revision_id = (int) $updated_entity->getRevisionId();
    // Assert that the entity was indeed created using the PATCHed values.     foreach ($this->getPatchDocument()['data']['attributes'] as $field_name => $field_normalization) {
      // If the value is an array of properties, only verify that the sent

  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. */

  public function title(RevisionableInterface $_entity_revision): TranslatableMarkup {
    $revision = $this->entityRepository->getTranslationFromContext($_entity_revision);
    $titleArgs = ['%title' => $revision->label()];
    if (!$revision instanceof RevisionLogInterface) {
      return $this->t('Revision of %title', $titleArgs);
    }

    $titleArgs['%date'] = $this->dateFormatter->format($revision->getRevisionCreationTime());
    return $this->t('Revision of %title from %date', $titleArgs);
  }

}
foreach ($blocks as $delta => $revision_id) {
      // Confirm the correct revision text appears.       /** @var \Drupal\block_content\BlockContentInterface $loaded */
      $loaded = $this->container->get('entity_type.manager')
        ->getStorage('block_content')
        ->loadRevision($revision_id);
      // Verify revision log is the same.       $this->assertEquals($logs[$delta]$loaded->getRevisionLogMessage()new FormattableMarkup('Correct log message found for revision @revision', ['@revision' => $loaded->getRevisionId()]));
      if ($delta > 0) {
        $this->assertInstanceOf(UserInterface::class$loaded->getRevisionUser());
        $this->assertIsNumeric($loaded->getRevisionUserId());
        $this->assertIsNumeric($loaded->getRevisionCreationTime());
      }
    }

    // Confirm that this is the default revision.     $this->assertTrue($loaded->isDefaultRevision(), 'Third block revision is the default one.');

    // Make a new revision and set it to not be default.     // This will create a new revision that is not "front facing".     // Save this as a non-default revision.     $loaded->setNewRevision();
    $loaded->isDefaultRevision(FALSE);
    
'enabled' => TRUE,
          'expanded' => FALSE,
          'external' => FALSE,
          'langcode' => 'en',
          'menu_name' => 'main',
          'parent' => NULL,
          'rediscover' => FALSE,
          'title' => 'Llama Gabilondo',
          'weight' => 0,
          'drupal_internal__id' => 1,
          'drupal_internal__revision_id' => 1,
          'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'revision_log_message' => NULL,
          // @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.           'revision_translation_affected' => TRUE,
        ],
        'relationships' => [
          'revision_user' => [
            'data' => NULL,
            'links' => [
              'related' => [
                'href' => $base_url->toString() . '/revision_user' . $version_query_string,
              ],
              

  public function getFormId() {
    return $this->revision->getEntityTypeId() . '_revision_revert';
  }

  /** * {@inheritdoc} */
  public function getQuestion() {
    return ($this->getEntity() instanceof RevisionLogInterface)
      ? $this->t('Are you sure you want to revert to the revision from %revision-date?', [
        '%revision-date' => $this->dateFormatter->format($this->getEntity()->getRevisionCreationTime()),
      ])
      : $this->t('Are you sure you want to revert the revision?');
  }

  /** * {@inheritdoc} */
  public function getCancelUrl() {
    return $this->getEntity()->getEntityType()->hasLinkTemplate('version-history') && $this->getEntity()->toUrl('version-history')->access($this->currentUser)
      ? $this->getEntity()->toUrl('version-history')
      : $this->getEntity()->toUrl();
  }

  protected function assertRevision(int $id, string $langcode, string $title, ?string $log, int $timestamp): void {
    $revision = $this->nodeStorage->loadRevision($id);
    $this->assertInstanceOf(NodeInterface::class$revision);
    $this->assertSame($title$revision->getTitle());
    $this->assertSame($langcode$revision->language()->getId());
    $this->assertSame($log$revision->revision_log->value);
    $this->assertSame($timestamp(int) $revision->getRevisionCreationTime());
  }

  /** * Tests the migration of node revisions with translated nodes. */
  public function testNodeRevisions() {
    $this->assertRevision(1, 'en', 'An English Node', NULL, 1441032132);
    $this->assertRevision(2, 'en', 'The thing about Deep Space 9 (1st rev)', 'DS9 1st rev', 1564543588);
    $this->assertRevision(4, 'is', 'is - The thing about Firefly (1st rev)', 'is - Firefly 1st rev', 1478755274);
    $this->assertRevision(6, 'en', 'Comments are closed :-(', NULL, 1504715414);
    $this->assertRevision(7, 'en', 'Comments are open :-)', NULL, 1504715432);
    
/** @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. */
'langcode' => 'en',
          'name' => 'Llama',
          'path' => [
            'alias' => '/llama',
            'pid' => 1,
            'langcode' => 'en',
          ],
          'weight' => 0,
          'drupal_internal__tid' => 1,
          'status' => TRUE,
          'drupal_internal__revision_id' => 1,
          'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'revision_log_message' => NULL,
          // @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518.           'revision_translation_affected' => TRUE,
        ],
        'relationships' => [
          'parent' => $expected_parent_normalization,
          'vid' => [
            'data' => [
              'id' => Vocabulary::load('camelids')->uuid(),
              'meta' => [
                'drupal_internal__target_id' => 'camelids',
              ],

        'attributes' => [
          'body' => [
            'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
            'format' => 'plain_text',
            'summary' => NULL,
            'processed' => "<p>The name &quot;llama&quot; was adopted by European settlers from native Peruvians.</p>\n",
          ],
          'changed' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'info' => 'Llama',
          'revision_log' => NULL,
          'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339),
          'revision_translation_affected' => TRUE,
          'status' => FALSE,
          'langcode' => 'en',
          'default_langcode' => TRUE,
          'drupal_internal__id' => 1,
          'drupal_internal__revision_id' => 1,
          'reusable' => TRUE,
        ],
        'relationships' => [
          'block_content_type' => [
            'data' => [
              
Home | Imprint | This part of the site doesn't use cookies.