diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 9e1d12f..d55f4ff 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -123,11 +123,7 @@ public function getControllerClass($entity_type, $controller_type, $nested = NUL * A storage controller instance. */ public function getStorageController($entity_type) { - if (!isset($this->controllers['storage'][$entity_type])) { - $class = $this->getControllerClass($entity_type, 'storage'); - $this->controllers['storage'][$entity_type] = new $class($entity_type); - } - return $this->controllers['storage'][$entity_type]; + return $this->getController($entity_type, 'storage'); } /** @@ -140,11 +136,7 @@ public function getStorageController($entity_type) { * A list controller instance. */ public function getListController($entity_type) { - if (!isset($this->controllers['listing'][$entity_type])) { - $class = $this->getControllerClass($entity_type, 'list'); - $this->controllers['listing'][$entity_type] = new $class($entity_type, $this->getStorageController($entity_type)); - } - return $this->controllers['listing'][$entity_type]; + return $this->getController($entity_type, 'list'); } /** @@ -161,7 +153,12 @@ public function getListController($entity_type) { public function getFormController($entity_type, $operation) { if (!isset($this->controllers['form'][$operation][$entity_type])) { $class = $this->getControllerClass($entity_type, 'form', $operation); - $this->controllers['form'][$operation][$entity_type] = new $class($operation); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers['form'][$operation][$entity_type] = $class::createInstance($this->container, $entity_type); + } + else { + $this->controllers['form'][$operation][$entity_type] = new $class($operation); + } } return $this->controllers['form'][$operation][$entity_type]; } @@ -176,11 +173,7 @@ public function getFormController($entity_type, $operation) { * A render controller instance. */ public function getRenderController($entity_type) { - if (!isset($this->controllers['render'][$entity_type])) { - $class = $this->getControllerClass($entity_type, 'render'); - $this->controllers['render'][$entity_type] = new $class($entity_type); - } - return $this->controllers['render'][$entity_type]; + return $this->getController($entity_type, 'render'); } /** @@ -193,11 +186,31 @@ public function getRenderController($entity_type) { * A access controller instance. */ public function getAccessController($entity_type) { - if (!isset($this->controllers['access'][$entity_type])) { + return $this->getController($entity_type, 'access'); + } + + /** + * Creates a new controller instance. + * + * @param string $entity_type + * The entity type for this access controller. + * @param string $controller_type + * The controller type to create an instance for. + * + * @return mixed + * A controller instance. + */ + protected function getController($entity_type, $controller_type) { + if (!isset($this->controllers[$controller_type][$entity_type])) { $class = $this->getControllerClass($entity_type, 'access'); - $this->controllers['access'][$entity_type] = new $class($entity_type); + if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { + $this->controllers[$controller_type][$entity_type] = $class::createInstance($this->container, $entity_type); + } + else { + $this->controllers[$controller_type][$entity_type] = new $class($entity_type); + } } - return $this->controllers['access'][$entity_type]; + return $this->controllers[$controller_type][$entity_type]; } /**