diff -u b/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php --- b/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -26,9 +26,7 @@ * {@inheritdoc} */ public function access(EntityInterface $entity, $operation, $langcode = Language::LANGUAGE_DEFAULT, AccountInterface $account = NULL) { - if (!$account) { - $account = $GLOBALS['user']; - } + $account = $this->prepareUser($account); if (($access = $this->getCache($entity, $operation, $langcode, $account)) !== NULL) { // Cache hit, no work necessary. @@ -71,2 +69,9 @@ + protected function prepareUser($account) { + if (!$account) { + $account = $GLOBALS['user']; + } + return $account; + } + /** diff -u b/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php --- b/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -31,7 +31,18 @@ return parent::access($entity, $operation, $langcode, $account); } - public function createAccess($type, $account = NULL) { + /** + * @param string $type + * The node type to check access for. + * @param \Drupal\Core\Session\AccountInterface $account + * (optional) The user session for which to check access, or NULL to check + * access for the current user. Defaults to NULL. + * @param array $context + * An array of key-value pairs to pass additional context when needed. + */ + public function createAccess($type, AccountInterface $account = NULL, $context = array()) { + $account = $this->prepareUser($account); + if (user_access('bypass node access', $account)) { return TRUE; } @@ -39,7 +50,7 @@ return FALSE; } - $access = module_invoke_all('node_create_access', $account); + $access = module_invoke_all('node_create_access', $account, $context); $configured_types = node_permissions_get_configured_types(); if (isset($configured_types[$type])) {