diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index 26530a6..4b67113 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -104,32 +104,6 @@ protected function access(EntityInterface $entity, $operation, $langcode = LANGU } /** - * Retrieves the cache id for the given entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity for which to check 'create' access. - * @param string $operation - * The entity operation. Usually one of 'view', 'edit', 'create' or - * 'delete'. - * @param string $langcode - * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. - * @param \Drupal\user\Plugin\Core\Entity\User $account - * (optional) The user for which to check access, or NULL to check access - * for the current user. Defaults to NULL. - * - * @return string - * The cache id as used by EntityAccessController::setCache() and - * EntityAccessController::getCache(). - */ - protected function cacheId(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { - // In some cases (e.g. 'create' access checks) the entity has not been saved - // yet and therefore does not have an id in which case we use the bundle as - // identifier for the cache entry. - return $entity->isNew() ? $entity->bundle() : $entity->id(); - } - - /** * Tries to retrieve a previously cached access value from the static cache. * * @param \Drupal\Core\Entity\EntityInterface $entity @@ -152,12 +126,12 @@ protected function cacheId(EntityInterface $entity, $operation, $langcode = LANG 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); - $cid = $this->cacheId($entity, $operation, $langcode, $account ?: NULL); $uid = $account ? $account->id() : 0; + $uuid = $entity->uuid(); // Return from cache if a value has been set for it previously. - if (isset($this->accessCache[$uid][$cid][$langcode][$operation])) { - return $this->accessCache[$uid][$cid][$langcode][$operation]; + if (isset($this->accessCache[$uid][$uuid][$langcode][$operation])) { + return $this->accessCache[$uid][$uuid][$langcode][$operation]; } } @@ -182,11 +156,11 @@ 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); - $cid = $this->cacheId($entity, $operation, $langcode, $account ?: NULL); $uid = $account ? $account->id() : 0; + $uuid = $entity->uuid(); // Save the given value in the static cache and directly return it. - return $this->accessCache[$uid][$cid][$langcode][$operation] = (bool) $access; + return $this->accessCache[$uid][$uuid][$langcode][$operation] = (bool) $access; } /**