Issue #2041333 by tstoeckler, tim.plunkett: Inject the module handler into the entity access controller.
parent
070b183e05
commit
9be3ce8858
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
|
@ -29,6 +30,13 @@ class EntityAccessController implements EntityAccessControllerInterface {
|
|||
*/
|
||||
protected $entityType;
|
||||
|
||||
/**
|
||||
* The module handler service.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ModuleHandlerInterface
|
||||
*/
|
||||
protected $moduleHandler;
|
||||
|
||||
/**
|
||||
* Constructs an access controller instance.
|
||||
*
|
||||
|
@ -58,7 +66,7 @@ class EntityAccessController implements EntityAccessControllerInterface {
|
|||
// 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 @@ class EntityAccessController implements EntityAccessControllerInterface {
|
|||
// 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->entity_type . '_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,12 @@ class EntityAccessController implements EntityAccessControllerInterface {
|
|||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setModuleHandler(ModuleHandlerInterface $module_handler) {
|
||||
$this->moduleHandler = $module_handler;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 @@ interface EntityAccessControllerInterface {
|
|||
*/
|
||||
public function resetCache();
|
||||
|
||||
/**
|
||||
* Sets the module handler for this form.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
*
|
||||
* @return self
|
||||
* The entity access controller.
|
||||
*/
|
||||
public function setModuleHandler(ModuleHandlerInterface $module_handler);
|
||||
|
||||
}
|
||||
|
|
|
@ -329,7 +329,11 @@ class EntityManager extends PluginManagerBase {
|
|||
* 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];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\node;
|
|||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Entity\EntityControllerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Entity\EntityAccessController;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
@ -31,13 +30,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 +37,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 +49,7 @@ class NodeAccessController extends EntityAccessController implements NodeAccessC
|
|||
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')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue