diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index 4658d50..59bdb85 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; @@ -30,6 +31,13 @@ class EntityAccessController implements EntityAccessControllerInterface { protected $entityType; /** + * The module handler service. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * Constructs an access controller instance. * * @param string $entity_type @@ -58,7 +66,7 @@ public function access(EntityInterface $entity, $operation, $langcode = Language // We grant access to the entity if both of these conditions are met: // - No modules say to deny access. // - At least one module says to grant access. - $access = module_invoke_all($entity->entityType() . '_access', $entity, $operation, $account, $langcode); + $access = $this->moduleHandler->invokeAll($entity->entityType() . '_access', array($entity, $operation, $account, $langcode)); if (($return = $this->processAccessHookResults($access)) === NULL) { // No module had an opinion about the access, so let's the access @@ -196,7 +204,7 @@ public function createAccess($entity_bundle = NULL, AccountInterface $account = // We grant access to the entity if both of these conditions are met: // - No modules say to deny access. // - At least one module says to grant access. - $access = module_invoke_all($this->entity_type . '_create_access', $account, $context['langcode']); + $access = $this->moduleHandler->invokeAll($this->entityType . '_create_access', array($account, $context['langcode'])); if (($return = $this->processAccessHookResults($access)) === NULL) { // No module had an opinion about the access, so let's the access @@ -244,4 +252,11 @@ protected function prepareUser(AccountInterface $account = NULL) { return $account; } + /** + * {@inheritdoc} + */ + public function setModuleHandler(ModuleHandlerInterface $module_handler) { + $this->moduleHandler = $module_handler; + } + } diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php index c0296dd..7b18354 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; @@ -58,4 +59,15 @@ public function createAccess($entity_bundle = NULL, AccountInterface $account = */ public function resetCache(); + /** + * Sets the module handler for this form. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + * + * @return self + * The entity form. + */ + public function setModuleHandler(ModuleHandlerInterface $module_handler); + } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 3060909..5f96165 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -315,7 +315,11 @@ public function getRenderController($entity_type) { * A access controller instance. */ public function getAccessController($entity_type) { - return $this->getController($entity_type, 'access'); + if (!isset($this->controllers['access'][$entity_type])) { + $controller = $this->getController($entity_type, 'access'); + $controller->setModuleHandler($this->moduleHandler); + } + return $this->controllers['access'][$entity_type]; } /** diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index b1f120a..944cd19 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -31,13 +31,6 @@ class NodeAccessController extends EntityAccessController implements NodeAccessC */ protected $grantStorage; - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - /** * Constructs a NodeAccessController object. * @@ -45,13 +38,10 @@ class NodeAccessController extends EntityAccessController implements NodeAccessC * The entity type of the access controller instance. * @param \Drupal\node\NodeGrantDatabaseStorageInterface $grant_storage * The node grant storage. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler to invoke the alter hook with. */ - public function __construct($entity_type, NodeGrantDatabaseStorageInterface $grant_storage, ModuleHandlerInterface $module_handler) { + public function __construct($entity_type, NodeGrantDatabaseStorageInterface $grant_storage) { parent::__construct($entity_type); $this->grantStorage = $grant_storage; - $this->moduleHandler = $module_handler; } /** @@ -60,8 +50,7 @@ public function __construct($entity_type, NodeGrantDatabaseStorageInterface $gra public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( $entity_type, - $container->get('node.grant_storage'), - $container->get('module_handler') + $container->get('node.grant_storage') ); }