Skip to content
Snippets Groups Projects
Verified Commit ab75cee9 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3384725 by acbramley, smustgrave: Add pagination to VersionHistoryController

(cherry picked from commit 9048b09b)
parent d0015fde
No related branches found
No related tags found
16 merge requests!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!5427Issue #3338518: send credentials in ajax if configured in CORS settings.,!5395Issue #3387916 by fjgarlin, Spokje: Each GitLab job exposes user email,!5217Issue #3386607 by alexpott: Improve spell checking in commit-code-check.sh,!5064Issue #3379522 by finnsky, Gauravvvv, kostyashupenko, smustgrave, Chi: Revert...,!5040SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception,!4958Issue #3392147: Whitelist IP for a Ban module.,!4894Issue #3280279: Add API to allow sites to opt in to upload SVG images in CKEditor 5,!4857Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!4856Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3679Issue #115801: Allow password on registration without disabling e-mail verification,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->),!925Issue #2339235: Remove taxonomy hard dependency on node module,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links
Pipeline #21278 failed
Pipeline: drupal

#21299

    Pipeline: drupal

    #21298

      Pipeline: drupal

      #21297

        ......@@ -25,6 +25,8 @@
        */
        class VersionHistoryController extends ControllerBase {
        const REVISIONS_PER_PAGE = 50;
        /**
        * Constructs a new VersionHistoryController.
        *
        ......@@ -213,6 +215,7 @@ protected function loadRevisions(RevisionableInterface $entity) {
        ->allRevisions()
        ->condition($entityType->getKey('id'), $entity->id())
        ->sort($entityType->getKey('revision'), 'DESC')
        ->pager(self::REVISIONS_PER_PAGE)
        ->execute();
        $currentLangcode = $this->languageManager
        ......@@ -249,6 +252,8 @@ protected function revisionOverview(RevisionableInterface $entity): array {
        $build['entity_revisions_table']['#rows'][$revision->getRevisionId()] = $this->buildRow($revision);
        }
        $build['pager'] = ['#type' => 'pager'];
        (new CacheableMetadata())
        // Only dealing with this entity and no external dependencies.
        ->addCacheableDependency($entity)
        ......
        ......@@ -2,6 +2,7 @@
        namespace Drupal\FunctionalTests\Entity;
        use Drupal\Core\Entity\Controller\VersionHistoryController;
        use Drupal\entity_test\Entity\EntityTestRev;
        use Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog;
        use Drupal\Tests\BrowserTestBase;
        ......@@ -323,4 +324,44 @@ public function testOperationDeleteRevision(): void {
        $this->assertSession()->elementExists('named', ['link', 'Delete'], $row1);
        }
        /**
        * Test revisions are paginated.
        */
        public function testRevisionsPagination(): void {
        /** @var \Drupal\entity_test\Entity\EntityTestRev $entity */
        $entity = EntityTestRev::create([
        'type' => 'entity_test_rev',
        'name' => 'view all revisions,view revision',
        ]);
        $entity->save();
        $firstRevisionId = $entity->getRevisionId();
        for ($i = 0; $i < VersionHistoryController::REVISIONS_PER_PAGE; $i++) {
        $entity->setNewRevision(TRUE);
        // We need to change something on the entity for it to be considered a new
        // revision to display. We need "view all revisions" and "view revision"
        // in a comma separated string to grant access.
        $entity->setName('view all revisions,view revision,' . $i)->save();
        }
        $this->drupalGet($entity->toUrl('version-history'));
        $this->assertSession()->elementsCount('css', 'table tbody tr', VersionHistoryController::REVISIONS_PER_PAGE);
        $this->assertSession()->elementExists('css', '.pager');
        /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
        $storage = $this->container->get('entity_type.manager')->getStorage($entity->getEntityTypeId());
        $firstRevision = $storage->loadRevision($firstRevisionId);
        $secondRevision = $storage->loadRevision($firstRevisionId + 1);
        // We should see everything up to the second revision, but not the first.
        $this->assertSession()->linkByHrefExists($secondRevision->toUrl('revision')->toString());
        $this->assertSession()->linkByHrefNotExists($firstRevision->toUrl('revision')->toString());
        // The next page should show just the first revision.
        $this->clickLink('Go to next page');
        $this->assertSession()->elementsCount('css', 'table tbody tr', 1);
        $this->assertSession()->elementExists('css', '.pager');
        $this->assertSession()->linkByHrefNotExists($secondRevision->toUrl('revision')->toString());
        $this->assertSession()->linkByHrefExists($firstRevision->toUrl('revision')->toString());
        }
        }
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment