diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index 4b67113..423281f 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -86,10 +86,13 @@ public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * * @return bool|null * TRUE if access was granted, FALSE if access was denied and NULL if access - * could not be reliably determined. + * could not be determined. */ protected function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { - $account = $account ?: user_load($GLOBALS['user']->uid); + // @todo Remove this once we can rely on $account. + if (!$account) { + $account = user_load($GLOBALS['user']->uid); + } // We grant access to the entity if both of these conditions are met: // - No modules say to deny access. @@ -125,7 +128,10 @@ protected function access(EntityInterface $entity, $operation, $langcode = LANGU */ protected function getCache(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { // @todo Remove this once we can rely on $account. - $account = $account ?: user_load($GLOBALS['user']->uid); + if (!$account) { + $account = user_load($GLOBALS['user']->uid); + } + $uid = $account ? $account->id() : 0; $uuid = $entity->uuid(); @@ -155,7 +161,10 @@ protected function getCache(EntityInterface $entity, $operation, $langcode = LAN */ protected function setCache($access, EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { // @todo Remove this once we can rely on $account. - $account = $account ?: user_load($GLOBALS['user']->uid); + if (!$account) { + $account = user_load($GLOBALS['user']->uid); + } + $uid = $account ? $account->id() : 0; $uuid = $entity->uuid(); diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index d27cc52..815c2ab 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -13,7 +13,7 @@ use Drupal\Core\Entity\EntityNG; /** - * Form controller for the node edit forms. + * Defines the access controller for the node entity type. */ class NodeAccessController extends EntityAccessController { @@ -31,7 +31,7 @@ public function viewAccess(EntityInterface $node, $langcode = LANGUAGE_DEFAULT, // If no modules implement hook_node_grants(), the default behavior is to // allow all users to view published nodes, so reflect that here. - $status = (bool) $node instanceof EntityNG ? $node->status : $node->get('status', $langcode)->value; + $status = $node instanceof EntityNG ? $node->getTranslation($langcode, FALSE)->status->value : $node->status; return $this->setCache($status, $node, 'view', $langcode, $account); } @@ -52,18 +52,22 @@ protected function access(EntityInterface $node, $operation, $langcode = LANGUAG }; // Fetch information from the node object if possible. - $node_status = isset($node->status) ? $node->status : NULL; - $node_uid = isset($node->uid) ? $node->uid : NULL; + $status = isset($node->status) ? $node->status : NULL; + $uid = isset($node->uid) ? $node->uid : NULL; // If it is a proper EntityNG object, use the proper methods. if ($node instanceof EntityNG) { - $node_status = $node->get('status', $langcode)->value; - $node_uid = $node->get('uid', $langcode)->value; + $status = $node->getTranslation($langcode, FALSE)->status->value; + $uid = $node->getTranslation($langcode, FALSE)->uid->value; } // Check if authors can view their own unpublished nodes. - if ($operation == 'view' && !$node_status && user_access('view own unpublished content', $account)) { - $account = $account ?: user_load($GLOBALS['user']->uid); - if ($account->id() != 0 && $account->id() == $node_uid) { + if ($operation == 'view' && !$status && user_access('view own unpublished content', $account)) { + // @todo Remove this once we can rely on $account. + if (!$account) { + $account = user_load($GLOBALS['user']->uid); + } + + if ($account->id() != 0 && $account->id() == $uid) { return TRUE; } }