summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-10-21 11:39:32 (GMT)
committerNathaniel Catchpole2016-10-21 11:39:32 (GMT)
commit5c9d1a92f167cd0a8a8b1b9c576b8d6ddbac76a7 (patch)
tree63c95f167f93822fa3a3f8eb034d44d8f38d32ba
parent99a55f04f28c73cf75dd84d591f753c68c261885 (diff)
Issue #2798521 by jamesrward, Manuel Garcia, mikeker, Lendude, przemek_leczycki, aklump, dawehner: Views result summary returns float number when using the mini pager
-rw-r--r--core/modules/views/src/Plugin/views/pager/Mini.php40
-rw-r--r--core/modules/views/src/Tests/Plugin/MiniPagerTest.php12
-rw-r--r--core/modules/views/tests/modules/views_test_config/test_views/views.view.test_mini_pager.yml23
3 files changed, 55 insertions, 20 deletions
diff --git a/core/modules/views/src/Plugin/views/pager/Mini.php b/core/modules/views/src/Plugin/views/pager/Mini.php
index 5f1750e..c6520f4 100644
--- a/core/modules/views/src/Plugin/views/pager/Mini.php
+++ b/core/modules/views/src/Plugin/views/pager/Mini.php
@@ -47,14 +47,17 @@ class Mini extends SqlBase {
public function query() {
parent::query();
- // Don't query for the next page if we have a pager that has a limited
- // amount of pages.
- if ($this->getItemsPerPage() > 0 && (empty($this->options['total_pages']) || ($this->getCurrentPage() < $this->options['total_pages']))) {
- // Increase the items in the query in order to be able to find out whether
- // there is another page.
- $limit = $this->view->query->getLimit();
- $limit += 1;
- $this->view->query->setLimit($limit);
+ // Only modify the query if we don't want to do a total row count
+ if (!$this->view->get_total_rows) {
+ // Don't query for the next page if we have a pager that has a limited
+ // amount of pages.
+ if ($this->getItemsPerPage() > 0 && (empty($this->options['total_pages']) || ($this->getCurrentPage() < $this->options['total_pages']))) {
+ // Increase the items in the query in order to be able to find out
+ // whether there is another page.
+ $limit = $this->view->query->getLimit();
+ $limit += 1;
+ $this->view->query->setLimit($limit);
+ }
}
}
@@ -69,19 +72,16 @@ class Mini extends SqlBase {
* {@inheritdoc}
*/
public function postExecute(&$result) {
- // In query() one more item might have been retrieved than necessary. If so,
- // the next link needs to be displayed and the item removed.
- if ($this->getItemsPerPage() > 0 && count($result) > $this->getItemsPerPage()) {
- array_pop($result);
- // Make sure the pager shows the next link by setting the total items to
- // the biggest possible number but prevent failing calculations like
- // ceil(PHP_INT_MAX) we take PHP_INT_MAX / 2.
- $total = PHP_INT_MAX / 2;
+ // Only modify the result if we didn't do a total row count
+ if (!$this->view->get_total_rows) {
+ $this->total_items = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
+ // query() checks if we need a next link by setting limit 1 record past
+ // this page If we got the extra record we need to remove it before we
+ // render the result.
+ if ($this->getItemsPerPage() > 0 && count($result) > $this->getItemsPerPage()) {
+ array_pop($result);
+ }
}
- else {
- $total = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
- }
- $this->total_items = $total;
}
/**
diff --git a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php b/core/modules/views/src/Tests/Plugin/MiniPagerTest.php
index f39a9d6..1a73b69 100644
--- a/core/modules/views/src/Tests/Plugin/MiniPagerTest.php
+++ b/core/modules/views/src/Tests/Plugin/MiniPagerTest.php
@@ -70,6 +70,18 @@ class MiniPagerTest extends PluginTestBase {
$this->assertText($this->nodes[18]->label());
$this->assertText($this->nodes[19]->label());
+ // Test @total value in result summary
+ $view = Views::getView('test_mini_pager');
+ $view->setDisplay('page_4');
+ $this->executeView($view);
+ $this->assertIdentical($view->get_total_rows, TRUE, 'The query was set to calculate the total number of rows.');
+ $this->assertEqual(count($this->nodes), $view->total_rows, 'The total row count is equal to the number of nodes.');
+
+ $this->drupalGet('test_mini_pager_total', array('query' => array('page' => 1)));
+ $this->assertText('of ' . count($this->nodes), 'The first page shows the total row count.');
+ $this->drupalGet('test_mini_pager_total', array('query' => array('page' => 6)));
+ $this->assertText('of ' . count($this->nodes), 'The last page shows the total row count.');
+
// Test a mini pager with just one item per page.
$this->drupalGet('test_mini_pager_one');
$this->assertText('››');
diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_mini_pager.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_mini_pager.yml
index e65ea4a..289f83d 100644
--- a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_mini_pager.yml
+++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_mini_pager.yml
@@ -118,3 +118,26 @@ display:
type: mini
options:
items_per_page: 0
+ page_4:
+ display_plugin: page
+ id: page_4
+ display_title: 'Page 4'
+ position: 4
+ display_options:
+ display_extenders: { }
+ path: test_mini_pager_total
+ empty: { }
+ defaults:
+ empty: false
+ header: false
+ header:
+ result:
+ id: result
+ table: views
+ field: result
+ relationship: none
+ group_type: group
+ admin_label: ''
+ empty: false
+ content: 'Displaying @start - @end of @total'
+ plugin_id: result