diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 33a741d..e07b4aa 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -47,7 +47,7 @@ function entity_get_info($entity_type = NULL) { 'fieldable' => FALSE, 'entity class' => 'Drupal\Core\Entity\Entity', 'controller class' => 'Drupal\Core\Entity\DatabaseStorageController', - 'list controller class' => 'Drupal\Core\Entity\EntityListControllerBase', + 'list controller class' => 'Drupal\Core\Entity\EntityListController', 'form controller class' => array( 'default' => 'Drupal\Core\Entity\EntityFormController', ), @@ -557,13 +557,7 @@ function entity_list_controller($entity_type) { } $info = entity_get_info($entity_type); - $class = $info['list controller class']; - // @todo Provide a non-abstract base implementation, see entity_get_info(). - if ($class == 'Drupal\Core\Entity\EntityListControllerBase') { - throw new \InvalidArgumentException("Missing list controller for '$entity_type'"); - } - $instances[$entity_type] = new $class($entity_type); return $instances[$entity_type]; } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 1d22278..bb86637 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -287,4 +287,24 @@ public function isDefaultRevision($new_value = NULL) { return $return; } + /** + * Implements Drupal\Core\Entity\EntityInterface::getOperations(). + */ + public function getOperations() { + $uri = $this->uri(); + $operations['edit'] = array( + 'title' => t('Edit'), + 'href' => $uri['path'] . '/edit', + 'options' => $uri['options'], + 'weight' => 10, + ); + $operations['delete'] = array( + 'title' => t('Delete'), + 'href' => $uri['path'] . '/delete', + 'options' => $uri['options'], + 'weight' => 100, + ); + return $operations; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index d8b6eae..d50df45 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -219,4 +219,13 @@ public function getRevisionId(); * $new_value was passed, the previous value is returned. */ public function isDefaultRevision($new_value = NULL); + + /** + * Provides an array of information to render operation links. + * + * @return array + * An array of operation link data. + */ + public function getOperations(); + } diff --git a/core/lib/Drupal/Core/Entity/EntityListControllerBase.php b/core/lib/Drupal/Core/Entity/EntityListController.php similarity index 91% rename from core/lib/Drupal/Core/Entity/EntityListControllerBase.php rename to core/lib/Drupal/Core/Entity/EntityListController.php index e251dcb..9f1df2a 100644 --- a/core/lib/Drupal/Core/Entity/EntityListControllerBase.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -2,15 +2,15 @@ /** * @file - * Definition of Drupal\Core\Entity\EntityListControllerBase. + * Definition of Drupal\Core\Entity\EntityListController. */ namespace Drupal\Core\Entity; /** - * Abstract base class for entity list controllers. + * Provides a generic implementation of an entity list controller. */ -abstract class EntityListControllerBase implements EntityListControllerInterface { +class EntityListController implements EntityListControllerInterface { /** * The entity storage controller class. @@ -83,7 +83,7 @@ public function buildRow(EntityInterface $entity) { */ public function buildOperations(EntityInterface $entity) { // Retrieve and sort operations. - $operations = $this->getOperations($entity); + $operations = $entity->getOperations(); uasort($operations, 'drupal_sort_weight'); $build = array( '#theme' => 'links', diff --git a/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php index d93d91c..ac45ffb 100644 --- a/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php @@ -28,16 +28,6 @@ public function getStorageController(); public function load(); /** - * Provides an array of information to render operation links. - * - * @return array - * An array of operation link data to use in buildOperations. - * - * @todo Operations are specific to the *Entity*, not the list. Move into the Entity class. - */ - public function getOperations(EntityInterface $entity); - - /** * Builds the header row. * * @return array diff --git a/core/modules/config/lib/Drupal/config/ConfigEntityListController.php b/core/modules/config/lib/Drupal/config/ConfigEntityListController.php index a674020..7320291 100644 --- a/core/modules/config/lib/Drupal/config/ConfigEntityListController.php +++ b/core/modules/config/lib/Drupal/config/ConfigEntityListController.php @@ -7,16 +7,16 @@ namespace Drupal\config; -use Drupal\Core\Entity\EntityListControllerBase; +use Drupal\Core\Entity\EntityListController; use Drupal\Core\Entity\EntityInterface; /** * Default list controller for ConfigEntity objects. */ -class ConfigEntityListController extends EntityListControllerBase { +class ConfigEntityListController extends EntityListController { /** - * Overrides Drupal\Core\Entity\EntityListControllerBase::load(). + * Overrides Drupal\Core\Entity\EntityListController::load(). */ public function load() { $entities = parent::load(); @@ -24,24 +24,4 @@ public function load() { return $entities; } - /** - * Implements Drupal\Core\Entity\EntityListControllerInterface::getOperations(). - */ - public function getOperations(EntityInterface $entity) { - $uri = $entity->uri(); - $operations['edit'] = array( - 'title' => t('edit'), - 'href' => $uri['path'] . '/edit', - 'options' => $uri['options'], - 'weight' => 10, - ); - $operations['delete'] = array( - 'title' => t('delete'), - 'href' => $uri['path'] . '/delete', - 'options' => $uri['options'], - 'weight' => 100, - ); - return $operations; - } - } diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index a75eff8..a6ceca7 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -180,33 +180,6 @@ function config_test_delete($id) { function config_test_list_page() { $controller = entity_list_controller('config_test'); return $controller->render(); - - $entities = entity_load_multiple('config_test'); - - $rows = array(); - foreach ($entities as $config_test) { - $uri = $config_test->uri(); - $row = array(); - $row['name']['data'] = array( - '#type' => 'link', - '#title' => $config_test->label(), - '#href' => $uri['path'], - '#options' => $uri['options'], - ); - $row['delete']['data'] = array( - '#type' => 'link', - '#title' => t('Delete'), - '#href' => $uri['path'] . '/delete', - '#options' => $uri['options'], - ); - $rows[] = $row; - } - $build = array( - '#theme' => 'table', - '#header' => array('Name', 'Operations'), - '#rows' => $rows, - ); - return $build; } /**