diff --git a/core/includes/entity.api.php b/core/includes/entity.api.php index 451e45e..5c993ac 100644 --- a/core/includes/entity.api.php +++ b/core/includes/entity.api.php @@ -546,7 +546,7 @@ function hook_entity_field_info_alter(&$info, $entity_type) { * @param \Drupal\Core\Entity\EntityInterface $entity * The entity on which the linked operations will be performed. */ -function hook_entity_operations_alter(array &$operations, \Drupal\Core\Entity\EntityStorageControllerInterface $entity) { +function hook_entity_operations_alter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity) { $uri = $entity->uri(); $operations['translate'] = array( 'title' => t('Translate'), diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index 09b30b8..b5a5f9c 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -7,10 +7,13 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; + /** * Provides a generic implementation of an entity list controller. */ -class EntityListController implements EntityListControllerInterface { +class EntityListController implements EntityListControllerInterface, EntityControllerInterface { /** * The entity storage controller class. @@ -20,6 +23,13 @@ class EntityListController implements EntityListControllerInterface { protected $storage; /** + * The module handler to invoke hooks on. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * The entity type name. * * @var string @@ -36,17 +46,34 @@ class EntityListController implements EntityListControllerInterface { protected $entityInfo; /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $entity_type, + $entity_info, + $container->get('plugin.manager.entity')->getStorageController($entity_type), + $container->get('module_handler') + ); + } + + /** * Constructs a new EntityListController object. * - * @param string $entity_type. + * @param string $entity_type * The type of entity to be listed. - * @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage. + * @param array $entity_info + * An array of entity info for the entity type. + * @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage * The entity storage controller class. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke hooks on. */ - public function __construct($entity_type, EntityStorageControllerInterface $storage) { + public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler) { $this->entityType = $entity_type; $this->storage = $storage; - $this->entityInfo = entity_get_info($this->entityType); + $this->entityInfo = $entity_info; + $this->moduleHandler = $module_handler; } /** @@ -131,7 +158,7 @@ public function buildRow(EntityInterface $entity) { public function buildOperations(EntityInterface $entity) { // Retrieve and sort operations. $operations = $this->getOperations($entity); - \Drupal::moduleHandler()->alter('entity_operation', $operations, $entity); + $this->moduleHandler->alter('entity_operation', $operations, $entity); uasort($operations, 'drupal_sort_weight'); $build = array( '#type' => 'operations',