Skip to content
Snippets Groups Projects
Commit 49eb672c authored by Florent Torregrosa's avatar Florent Torregrosa
Browse files

Issue #3381979 by Lendude, akshay_d, smustgrave, francismak: More link is...

Issue #3381979 by Lendude, akshay_d, smustgrave, francismak: More link is missing in pager when using the "Some" pager and there are more records than shown
parent fb2469d3
No related branches found
No related tags found
1 merge request!9063Issue #3381979 by Lendude, akshay_d, smustgrave, francismak: More link is...
......@@ -19,6 +19,13 @@
)]
class Some extends PagerPluginBase {
/**
* Total number of items in the result set before the pager limit is applied.
*
* @var int
*/
protected int $totalItemsBeforePagerLimit;
public function summaryTitle() {
if (!empty($this->options['offset'])) {
return $this->formatPlural($this->options['items_per_page'], '@count item, skip @skip', '@count items, skip @skip', ['@count' => $this->options['items_per_page'], '@skip' => $this->options['offset']]);
......@@ -74,7 +81,23 @@ public function query() {
* {@inheritdoc}
*/
public function postExecute(&$result): void {
$this->totalItemsBeforePagerLimit = $this->total_items;
$this->total_items = count($result);
}
/**
* {@inheritdoc}
*/
public function hasMoreRecords() {
// Determine if there are more records by comparing the total number of
// items to the items per page.
$totalItems = $this->totalItemsBeforePagerLimit ?? $this->total_items;
if ($this->getItemsPerPage() && ($totalItems > $this->getItemsPerPage())) {
return TRUE;
}
else {
return FALSE;
}
}
}
<?php
declare(strict_types=1);
namespace Drupal\Tests\views\Kernel\Plugin;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the "Some" pager.
*
* @group views
*/
class SomePagerTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = ['test_tokens'];
/**
* Tests that the "more" link works correctly with the "Some" pager.
*
* @see \Drupal\views\Plugin\views\pager\Some::hasMoreRecords()
*/
public function testSomeHasMoreRecords(): void {
$view = Views::getView('test_tokens');
$view->setDisplay('page_4');
$this->executeView($view);
$total_rows_in_table = ViewTestData::dataSet();
$this->assertSame(3, $view->total_rows);
$this->assertGreaterThan(3, count($total_rows_in_table));
$this->assertTrue($view->getPager()->hasMoreRecords());
}
}
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