diff --git a/core/lib/Drupal/Core/Entity/EntityDefaultOperationsController.php b/core/lib/Drupal/Core/Entity/EntityDefaultOperationsController.php index 82559c8..f3b3215 100644 --- a/core/lib/Drupal/Core/Entity/EntityDefaultOperationsController.php +++ b/core/lib/Drupal/Core/Entity/EntityDefaultOperationsController.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity; -use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -15,7 +14,8 @@ /** * Defines a default entity operations controller. */ -class EntityDefaultsOperationsController implements EntityOperationsControllerInterface, EntityControllerInterface { +class EntityDefaultsOperationsController implements EntityOperationsControllerInterface { + /** * The module handler. * @@ -24,19 +24,17 @@ class EntityDefaultsOperationsController implements EntityOperationsControllerIn protected $moduleHandler; /** - * Creates a EntityDefaultsOperationsController object. + * Sets the module handler for this form. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + * + * @return self + * The entity access controller. */ - public function __construct(ModuleHandlerInterface $module_handler) { + public function setModuleHandler(ModuleHandlerInterface $module_handler) { $this->moduleHandler = $module_handler; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { - return new static($container->get('module_handler')); + return $this; } /** @@ -68,7 +66,7 @@ public function getOperations(EntityInterface $entity) { $operations = $this->getOwnOperations($entity); $hooks = array($entity->entityType() . '_operations' , 'entity_operations'); foreach ($hooks as $hook) { - $operations = array_merge($operations, $this->moduleHandler->invokeAll($hook, $entity)); + $operations = array_merge($operations, $this->moduleHandler->invokeAll($hook, array($entity))); } // Check whether the operations are accessible. @@ -82,4 +80,5 @@ public function getOperations(EntityInterface $entity) { return $operations; } + } diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index 0006844..53551b7 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -85,14 +85,10 @@ public static function createInstance(ContainerInterface $container, $entity_typ * The entity storage controller class. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke hooks on. - * @param \Drupal\Core\Entity\EntityOperationsControllerInterface $operations - * The entity operations controller class. - */ - public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, EntityOperationsControllerInterface $operations, ModuleHandlerInterface $module_handler) { + public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler) { $this->entityType = $entity_type; $this->storage = $storage; - $this->operations = $operations; $this->entityInfo = $entity_info; $this->moduleHandler = $module_handler; } @@ -241,4 +237,12 @@ public function setTranslationManager(TranslationInterface $translation_manager) return $this; } + /** + * {@inheritdoc} + */ + public function setOperationsController(EntityOperationsControllerInterface $operations) { + $this->operations = $operations; + return $this; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php index b7581d8..62f9df9 100644 --- a/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityListControllerInterface.php @@ -48,6 +48,17 @@ public function load(); public function getOperations(EntityInterface $entity); /** + * Sets the entity operations controller. + * + * @param \Drupal\Core\Entity\EntityOperationsControllerInterface $operations + * The entity operations controller. + * + * @return self + * The entity list controller. + */ + public function setOperationsController(EntityOperationsControllerInterface $operations); + + /** * Renders the list page markup to be output. * * @return string diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 3971aff..936becb 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -267,11 +267,13 @@ public function getListController($entity_type) { if (!isset($this->controllers['listing'][$entity_type])) { $class = $this->getControllerClass($entity_type, 'list'); if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { - $this->controllers['listing'][$entity_type] = $class::createInstance($this->container, $entity_type, $this->getDefinition($entity_type)); + $controller = $class::createInstance($this->container, $entity_type, $this->getDefinition($entity_type)); } else { - $this->controllers['listing'][$entity_type] = new $class($entity_type, $this->getStorageController($entity_type)); + $controller = new $class($entity_type, $this->getStorageController($entity_type)); } + $controller->setOperationsController($this->getOperationsController($entity_type)); + $this->controllers['listing'][$entity_type] = $controller; } return $this->controllers['listing'][$entity_type]; } @@ -339,16 +341,20 @@ public function getAccessController($entity_type) { /** * Gets an entity type's operations controller. * + * @param string $entity_type + * The entity type for this operations controller. + * * @return \Drupal\Core\Entity\EntityOperationsControllerInterface. */ public function getOperationsController($entity_type) { - return $this->getController($entity_type, 'operations'); + if (!isset($this->controllers['operations'][$entity_type])) { + $controller = $this->getController($entity_type, 'operations'); + $controller->setModuleHandler($this->moduleHandler); + } + return $this->controllers['operations'][$entity_type]; } /** - - - /** * Creates a new controller instance. * * @param string $entity_type