Skip to content
Snippets Groups Projects
Commit feaddcd0 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1830822 by tim.plunkett, xjm: Split the Views UI listing into two...

Issue #1830822 by tim.plunkett, xjm: Split the Views UI listing into two tables for enabled and disabled.
parent f14f63cc
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -115,6 +115,37 @@ function testDefaultViews() {
$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.
*
......
......@@ -1158,3 +1158,7 @@ div.messages {
}
/* @end */
.views-list-section {
margin-bottom: 2em;
}
......@@ -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;
}
else {
$entities['disabled'][] = $entity;
}
return $a->id() > $b->id();
});
}
return $entities;
}
......@@ -156,10 +159,30 @@ public function buildOperations(EntityInterface $entity) {
* 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'] = '<h2>' . t('Enabled') . '</h2>';
$list['disabled']['heading']['#markup'] = '<h2>' . t('Disabled') . '</h2>';
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;
}
......
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