Issue #2508966 by giancarlosotelo, geertvd, tim.plunkett, Berdir: List of Views limited to 50 items

8.0.x
Alex Pott 2015-08-07 14:26:43 +01:00
parent 6cd78a1369
commit 99a340dd0f
3 changed files with 88 additions and 11 deletions

View File

@ -40,9 +40,12 @@ class EntityListBuilder extends EntityHandlerBase implements EntityListBuilderIn
protected $entityType;
/**
* The number of entities to list per page.
* The number of entities to list per page, or FALSE to list all entities.
*
* @var int
* For example, set this to FALSE if the list uses client-side filters that
* require all entities to be listed (like the views overview).
*
* @var int|false
*/
protected $limit = 50;
@ -92,12 +95,14 @@ class EntityListBuilder extends EntityHandlerBase implements EntityListBuilderIn
* An array of entity IDs.
*/
protected function getEntityIds() {
$query = $this->getStorage()->getQuery();
$keys = $this->entityType->getKeys();
return $query
->sort($keys['id'])
->pager($this->limit)
->execute();
$query = $this->getStorage()->getQuery()
->sort($this->entityType->getKey('id'));
// Only add the pager if a limit is specified.
if ($this->limit) {
$query->pager($this->limit);
}
return $query->execute();
}
/**
@ -227,9 +232,13 @@ class EntityListBuilder extends EntityHandlerBase implements EntityListBuilderIn
$build['table']['#rows'][$entity->id()] = $row;
}
}
// Only add the pager if a limit is specified.
if ($this->limit) {
$build['pager'] = array(
'#type' => 'pager',
);
}
return $build;
}

View File

@ -0,0 +1,58 @@
<?php
/**
* @file
* Contains \Drupal\views_ui\Tests\ViewsListTest.
*/
namespace Drupal\views_ui\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\views\Entity\View;
use Drupal\views\Views;
/**
* Tests the views list.
*
* @group views_ui
*/
class ViewsListTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views_ui');
/**
* Tests that the views list does not use a pager.
*/
public function testViewsListLimit() {
// Login.
$user = $this->createUser(['administer views']);
$this->drupalLogin($user);
// Check if we can access the main views admin page.
$this->drupalGet('admin/structure/views');
$this->assertText(t('Add new view'));
// Count default views to be subtracted from the limit.
$views = count(Views::getEnabledViews());
// Create multiples views.
$limit = 51;
$values = $this->config('views.view.test_view_storage')->get();
for ($i = 1; $i <= $limit - $views; $i++) {
$values['id'] = 'test_view_storage_new' . $i;
unset($values['uuid']);
$created = View::create($values);
$created->save();
}
$this->drupalGet('admin/structure/views');
// Check that all the rows are listed.
$this->assertEqual(count($this->xpath('//tbody/tr[contains(@class,"views-ui-list-enabled")]')), $limit);
}
}

View File

@ -30,6 +30,11 @@ class ViewListBuilder extends ConfigEntityListBuilder {
*/
protected $displayManager;
/**
* {@inheritdoc}
*/
protected $limit;
/**
* {@inheritdoc}
*/
@ -55,6 +60,11 @@ class ViewListBuilder extends ConfigEntityListBuilder {
parent::__construct($entity_type, $storage);
$this->displayManager = $display_manager;
// This list builder uses client-side filters which requires all entities to
// be listed, disable the pager.
// @todo https://www.drupal.org/node/2536826 change the filtering to support
// a pager.
$this->limit = FALSE;
}
/**