.../Drupal/Core/Entity/EntityAccessController.php | 32 ++++++++++++++++++---- core/lib/Drupal/Core/Entity/EntityNG.php | 10 +++---- .../lib/Drupal/block/BlockAccessController.php | 9 ++++-- .../node/lib/Drupal/node/NodeAccessController.php | 21 +++++--------- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index 164b83e..db42b06 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -7,13 +7,15 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a default implementation for entity access controllers. */ -class EntityAccessController implements EntityAccessControllerInterface { +class EntityAccessController implements EntityAccessControllerInterface, EntityControllerInterface { /** * Stores calculcated access check results. @@ -30,13 +32,33 @@ class EntityAccessController implements EntityAccessControllerInterface { protected $entityType; /** + * The module handler + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** * Constructs an access controller instance. * * @param string $entity_type * The entity type of the access controller instance. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke access hooks with. + */ + public function __construct($entity_type, ModuleHandlerInterface $module_handler) { + $this->entityType = $entity_type; + $this->moduleHandler = $module_handler; + } + + /** + * {@inheritdoc} */ - public function __construct($entity_type) { - $this->entity_type = $entity_type; + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $entity_type, + $container->get('module_handler') + ); } /** @@ -58,7 +80,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->getBCEntity(), $operation, $account, $langcode); + $access = $this->moduleHandler->invokeAll($entity->entityType() . '_access', array($entity->getBCEntity(), $operation, $account, $langcode)); if (($return = $this->processAccessHookResults($access)) === NULL) { // No module had an opinion about the access, so let's the access @@ -196,7 +218,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 diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index ac975d1..c6df9c1 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -413,14 +413,12 @@ public function isEmpty() { * {@inheritdoc} */ public function access($operation = 'view', AccountInterface $account = NULL) { + $access_controller = \Drupal::entityManager()->getAccessController($this->entityType); + if ($operation == 'create') { - return \Drupal::entityManager() - ->getAccessController($this->entityType) - ->createAccess($this->bundle(), $account); + return $access_controller->createAccess($this->bundle(), $account); } - return \Drupal::entityManager() - ->getAccessController($this->entityType) - ->access($this, $operation, $this->activeLangcode, $account); + return $access_controller->access($this, $operation, $this->activeLangcode, $account); } /** diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index 26716c2..fb44686 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityControllerInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Path\AliasManagerInterface; use Drupal\Component\Utility\Unicode; @@ -32,11 +33,14 @@ class BlockAccessController extends EntityAccessController implements EntityCont * * @param string $entity_type * The entity type of the access controller instance. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke access hooks with. * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager * The alias manager. */ - public function __construct($entity_type, AliasManagerInterface $alias_manager) { - parent::__construct($entity_type); + public function __construct($entity_type, ModuleHandlerInterface $module_handler, AliasManagerInterface $alias_manager) { + parent::__construct($entity_type, $module_handler); + $this->aliasManager = $alias_manager; } @@ -46,6 +50,7 @@ public function __construct($entity_type, AliasManagerInterface $alias_manager) public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( $entity_type, + $container->get('module_handler'), $container->get('path.alias_manager') ); } diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index b1f120a..4dcb911 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -31,27 +31,20 @@ class NodeAccessController extends EntityAccessController implements NodeAccessC */ protected $grantStorage; - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - /** * Constructs a NodeAccessController object. * * @param string $entity_type * The entity type of the access controller instance. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler to invoke access hooks with. * @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) { - parent::__construct($entity_type); + public function __construct($entity_type, ModuleHandlerInterface $module_handler, NodeGrantDatabaseStorageInterface $grant_storage) { + parent::__construct($entity_type, $module_handler); + $this->grantStorage = $grant_storage; - $this->moduleHandler = $module_handler; } /** @@ -60,8 +53,8 @@ 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('module_handler'), + $container->get('node.grant_storage') ); }