revisionIds example

->condition('vid', $nodes[2]->getRevisionId())
      ->fields([
        'revision_timestamp' => $old_revision_date,
      ])
      ->execute();
    $this->drupalGet("node/" . $node->id() . "/revisions/" . $nodes[2]->getRevisionId() . "/revert");
    $this->submitForm([], 'Revert');
    $this->assertSession()->pageTextContains("Basic page {$nodes[2]->label()} has been reverted to the revision from {$this->container->get('date.formatter')->format($old_revision_date)}.");

    // Confirm user is redirected depending on the remaining revisions,     // when a revision is deleted.     $existing_revision_ids = $node_storage->revisionIds($node);
    // Delete all revision except last 3.     $remaining_revision_ids = array_slice($existing_revision_ids, -3, 3);
    foreach ($existing_revision_ids as $revision_id) {
      if (!in_array($revision_id$remaining_revision_ids)) {
        $node_storage->deleteRevision($revision_id);
      }
    }

    // Confirm user was redirected to revisions history page.     $this->drupalGet("node/" . $node->id() . "/revisions/" . $remaining_revision_ids[0] . "/delete");
    $this->submitForm([], 'Delete');
    
$this->messenger()
      ->addStatus($this->t('Revision from %revision-date of @type %title has been deleted.', [
        '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime()),
        '@type' => $node_type,
        '%title' => $this->revision->label(),
      ]));
    // Set redirect to the revisions history page.     $route_name = 'entity.node.version_history';
    $parameters = ['node' => $this->revision->id()];
    // If no revisions found, or the user does not have access to the revisions     // page, then redirect to the canonical node page instead.     if (!$this->accessManager->checkNamedRoute($route_name$parameters) || count($this->nodeStorage->revisionIds($this->revision)) === 1) {
      $route_name = 'entity.node.canonical';
    }
    $form_state->setRedirect($route_name$parameters);
  }

}
$page->save();

    // Verify normal loads return the still-default previous version.     $page = Node::load($id);
    $this->assertEquals('B', $page->getTitle());

    // Verify we can load the pending revision, even if the mechanism is kind     // of gross. Note: revisionIds() is only available on NodeStorageInterface,     // so this won't work for non-nodes. We'd need to use entity queries. This     // is a core bug that should get fixed.     $storage = \Drupal::entityTypeManager()->getStorage('node');
    $revision_ids = $storage->revisionIds($page);
    sort($revision_ids);
    $latest = end($revision_ids);
    $page = $storage->loadRevision($latest);
    $this->assertEquals('C', $page->getTitle());

    $page->setTitle('D');
    $page->moderation_state->value = 'published';
    $page->save();

    // Verify normal loads return the still-default previous version.     $page = Node::load($id);
    
Home | Imprint | This part of the site doesn't use cookies.