Commit 45e492dc authored by webchick's avatar webchick

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

This reverts commit 135f4e6a.

Needs more discussion.
parent cb829e19
......@@ -7,15 +7,13 @@
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, EntityControllerInterface {
class EntityAccessController implements EntityAccessControllerInterface {
/**
* Stores calculcated access check results.
......@@ -31,34 +29,14 @@ class EntityAccessController implements EntityAccessControllerInterface, EntityC
*/
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 static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$entity_type,
$container->get('module_handler')
);
public function __construct($entity_type) {
$this->entity_type = $entity_type;
}
/**
......@@ -80,7 +58,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 = $this->moduleHandler->invokeAll($entity->entityType() . '_access', array($entity, $operation, $account, $langcode));
$access = module_invoke_all($entity->entityType() . '_access', $entity, $operation, $account, $langcode);
if (($return = $this->processAccessHookResults($access)) === NULL) {
// No module had an opinion about the access, so let's the access
......@@ -218,7 +196,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 = $this->moduleHandler->invokeAll($this->entityType . '_create_access', array($account, $context['langcode']));
$access = module_invoke_all($this->entity_type . '_create_access', $account, $context['langcode']);
if (($return = $this->processAccessHookResults($access)) === NULL) {
// No module had an opinion about the access, so let's the access
......
......@@ -413,12 +413,14 @@ public function isEmpty() {
* {@inheritdoc}
*/
public function access($operation = 'view', AccountInterface $account = NULL) {
$access_controller = \Drupal::entityManager()->getAccessController($this->entityType);
if ($operation == 'create') {
return $access_controller->createAccess($this->bundle(), $account);
return \Drupal::entityManager()
->getAccessController($this->entityType)
->createAccess($this->bundle(), $account);
}
return $access_controller->access($this, $operation, $this->activeLangcode, $account);
return \Drupal::entityManager()
->getAccessController($this->entityType)
->access($this, $operation, $this->activeLangcode, $account);
}
/**
......
......@@ -10,7 +10,6 @@
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;
......@@ -33,14 +32,11 @@ 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, ModuleHandlerInterface $module_handler, AliasManagerInterface $alias_manager) {
parent::__construct($entity_type, $module_handler);
public function __construct($entity_type, AliasManagerInterface $alias_manager) {
parent::__construct($entity_type);
$this->aliasManager = $alias_manager;
}
......@@ -50,7 +46,6 @@ public function __construct($entity_type, ModuleHandlerInterface $module_handler
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,20 +31,27 @@ 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, ModuleHandlerInterface $module_handler, NodeGrantDatabaseStorageInterface $grant_storage) {
parent::__construct($entity_type, $module_handler);
public function __construct($entity_type, NodeGrantDatabaseStorageInterface $grant_storage, ModuleHandlerInterface $module_handler) {
parent::__construct($entity_type);
$this->grantStorage = $grant_storage;
$this->moduleHandler = $module_handler;
}
/**
......@@ -53,8 +60,8 @@ public function __construct($entity_type, ModuleHandlerInterface $module_handler
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$entity_type,
$container->get('module_handler'),
$container->get('node.grant_storage')
$container->get('node.grant_storage'),
$container->get('module_handler')
);
}
......
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