From feaddcd0a87ef66cddf020e8d72421772323efd5 Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 26 Nov 2012 11:00:41 -0800 Subject: [PATCH] Issue #1830822 by tim.plunkett, xjm: Split the Views UI listing into two tables for enabled and disabled. --- .../views/Tests/UI/DefaultViewsTest.php | 31 ++++++++++++++ .../views/views_ui/css/views-admin.theme.css | 4 ++ .../Drupal/views_ui/ViewListController.php | 41 +++++++++++++++---- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/DefaultViewsTest.php index a274311f1bf..590bc6ef937 100644 --- a/core/modules/views/lib/Drupal/views/Tests/UI/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/UI/DefaultViewsTest.php @@ -115,6 +115,37 @@ class DefaultViewsTest extends UITestBase { $this->assertNoLinkByHref($edit_href); } + /** + * Tests that enabling views moves them to the correct table. + */ + function testSplitListing() { + // Build a re-usable xpath query. + $xpath = '//div[@id="views-entity-list"]/div[@class = :status]/table//tr[@title = :title]'; + $arguments = array( + ':status' => 'views-list-section enabled', + ':title' => t('Machine name: test_view_status'), + ); + + $this->drupalGet('admin/structure/views'); + + $elements = $this->xpath($xpath, $arguments); + $this->assertIdentical(count($elements), 0, 'A disabled view is not found in the enabled views table.'); + + $arguments[':status'] = 'views-list-section disabled'; + $elements = $this->xpath($xpath, $arguments); + $this->assertIdentical(count($elements), 1, 'A disabled view is found in the disabled views table.'); + + // Enable the view. + $this->clickViewsOperationLink(t('Enable'), '/test_view_status/'); + + $elements = $this->xpath($xpath, $arguments); + $this->assertIdentical(count($elements), 0, 'After enabling a view, it is not found in the disabled views table.'); + + $arguments[':status'] = 'views-list-section enabled'; + $elements = $this->xpath($xpath, $arguments); + $this->assertIdentical(count($elements), 1, 'After enabling a view, it is found in the enabled views table.'); + } + /** * Click a link to perform an operation on a view. * diff --git a/core/modules/views/views_ui/css/views-admin.theme.css b/core/modules/views/views_ui/css/views-admin.theme.css index d309edc489b..a565b473ca6 100644 --- a/core/modules/views/views_ui/css/views-admin.theme.css +++ b/core/modules/views/views_ui/css/views-admin.theme.css @@ -1158,3 +1158,7 @@ div.messages { } /* @end */ + +.views-list-section { + margin-bottom: 2em; +} diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php index a3e2bea4c22..46c139b8a3d 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -19,15 +19,18 @@ class ViewListController extends EntityListController { * Overrides Drupal\Core\Entity\EntityListController::load(); */ public function load() { - $entities = parent::load(); - uasort($entities, function ($a, $b) { - $a_enabled = $a->isEnabled(); - $b_enabled = $b->isEnabled(); - if ($a_enabled != $b_enabled) { - return $a_enabled < $b_enabled; + $entities = array( + 'enabled' => array(), + 'disabled' => array(), + ); + foreach (parent::load() as $entity) { + if ($entity->isEnabled()) { + $entities['enabled'][] = $entity; } - return $a->id() > $b->id(); - }); + else { + $entities['disabled'][] = $entity; + } + } return $entities; } @@ -156,10 +159,30 @@ class ViewListController extends EntityListController { * Overrides Drupal\Core\Entity\EntityListController::render(); */ public function render() { - $list = parent::render(); + $entities = $this->load(); + $list['#type'] = 'container'; $list['#attached']['css'] = ViewFormControllerBase::getAdminCSS(); $list['#attached']['library'][] = array('system', 'drupal.ajax'); $list['#attributes']['id'] = 'views-entity-list'; + $list['enabled']['heading']['#markup'] = '

' . t('Enabled') . '

'; + $list['disabled']['heading']['#markup'] = '

' . t('Disabled') . '

'; + foreach (array('enabled', 'disabled') as $status) { + $list[$status]['#type'] = 'container'; + $list[$status]['#attributes'] = array('class' => array('views-list-section', $status)); + $list[$status]['table'] = array( + '#theme' => 'table', + '#header' => $this->buildHeader(), + '#rows' => array(), + ); + foreach ($entities[$status] as $entity) { + $list[$status]['table']['#rows'][$entity->id()] = $this->buildRow($entity); + } + } + // @todo Use a placeholder for the entity label if this is abstracted to + // other entity types. + $list['enabled']['table']['#empty'] = t('There are no enabled views.'); + $list['disabled']['table']['#empty'] = t('There are no disabled views.'); + return $list; }