Commit 135f4e6a authored by webchick's avatar webchick

Issue #2041333 by tstoeckler: Inject the module handler into the entity access controller.

parent d02d037e
......@@ -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.
......@@ -29,14 +31,34 @@ 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, $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 +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
......
......@@ -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);
}
/**
......
......@@ -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')
);
}
......
......@@ -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')
);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment