From 66e6eb8d36ce7ebc9f22fb147bb53ef969b92265 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Sun, 19 May 2013 12:17:43 -0700 Subject: [PATCH] Issue #1994910 by tim.plunkett, twistor: Fixed ConfigEntity listing should only show enable/disable if status is supported. --- .../Entity/ConfigEntityListController.php | 32 ++++++++++--------- .../config/Tests/ConfigEntityListTest.php | 30 +++++++++++++++++ .../config/config_test.no_status.default.yml | 2 ++ .../tests/config_test/config_test.module | 5 +++ .../lib/Drupal/user/RoleListController.php | 1 - 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 core/modules/config/tests/config_test/config/config_test.no_status.default.yml diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index 4ef691197840..c4fa043a4234 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -31,21 +31,23 @@ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); $uri = $entity->uri(); - if (!$entity->status()) { - $operations['enable'] = array( - 'title' => t('Enable'), - 'href' => $uri['path'] . '/enable', - 'options' => $uri['options'], - 'weight' => -10, - ); - } - else { - $operations['disable'] = array( - 'title' => t('Disable'), - 'href' => $uri['path'] . '/disable', - 'options' => $uri['options'], - 'weight' => 20, - ); + if (isset($this->entityInfo['entity_keys']['status'])) { + if (!$entity->status()) { + $operations['enable'] = array( + 'title' => t('Enable'), + 'href' => $uri['path'] . '/enable', + 'options' => $uri['options'], + 'weight' => -10, + ); + } + else { + $operations['disable'] = array( + 'title' => t('Disable'), + 'href' => $uri['path'] . '/disable', + 'options' => $uri['options'], + 'weight' => 20, + ); + } } return $operations; diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php index f851cbc2500a..b67cb4a20504 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -98,6 +98,36 @@ function testList() { ); $actual_items = $controller->buildRow($entity); $this->assertIdentical($expected_items, $actual_items, 'Return value from buildRow matches expected.'); + + // Test that config entities that do not support status, do not have + // enable/disable operations. + $controller = $this->container->get('plugin.manager.entity') + ->getListController('config_test_no_status'); + + $list = $controller->load(); + $entity = $list['default']; + + // Test getOperations() method. + $uri = $entity->uri(); + $expected_operations = array( + 'edit' => array( + 'title' => t('Edit'), + 'href' => $uri['path'] . '/edit', + 'options' => $uri['options'], + 'weight' => 10, + ), + 'delete' => array( + 'title' => t('Delete'), + 'href' => $uri['path'] . '/delete', + 'options' => $uri['options'], + 'weight' => 100, + ), + ); + + $actual_operations = $controller->getOperations($entity); + // Sort the operations to normalize link order. + uasort($actual_operations, 'drupal_sort_weight'); + $this->assertIdentical($expected_operations, $actual_operations); } /** diff --git a/core/modules/config/tests/config_test/config/config_test.no_status.default.yml b/core/modules/config/tests/config_test/config/config_test.no_status.default.yml new file mode 100644 index 000000000000..3e50e3bbd3de --- /dev/null +++ b/core/modules/config/tests/config_test/config/config_test.no_status.default.yml @@ -0,0 +1,2 @@ +id: default +label: Default diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index c2c004c121e1..9949d90e595b 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -181,4 +181,9 @@ function config_test_entity_info_alter(&$entity_info) { // case we can safely do it because we set it once and we do not change it for // all the duration of the test session. $entity_info['config_test']['translatable'] = Drupal::service('state')->get('config_test.translatable'); + + // Create a clone of config_test that does not have a status. + $entity_info['config_test_no_status'] = $entity_info['config_test']; + unset($entity_info['config_test_no_status']['entity_keys']['status']); + $entity_info['config_test_no_status']['config_prefix'] = 'config_test.no_status'; } diff --git a/core/modules/user/lib/Drupal/user/RoleListController.php b/core/modules/user/lib/Drupal/user/RoleListController.php index 177b2d67cf1b..9ff5c8353e3d 100644 --- a/core/modules/user/lib/Drupal/user/RoleListController.php +++ b/core/modules/user/lib/Drupal/user/RoleListController.php @@ -48,7 +48,6 @@ public function getOperations(EntityInterface $entity) { // Built-in roles could not be deleted or disabled. if (in_array($entity->id(), array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { unset($operations['delete']); - unset($operations['disable']); } return $operations; } -- GitLab