Commit 66e6eb8d authored by alexpott's avatar alexpott

Issue #1994910 by tim.plunkett, twistor: Fixed ConfigEntity listing should...

Issue #1994910 by tim.plunkett, twistor: Fixed ConfigEntity listing should only show enable/disable if status is supported.
parent 071dccf6
......@@ -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;
......
......@@ -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);
}
/**
......
......@@ -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';
}
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment