| @@ 89-112 (lines=24) @@ | ||
| 86 | protected function resolveValues($value, array $args, ResolveInfo $info) { |
|
| 87 | $resolver = $this->entityBuffer->add($this->getPluginDefinition()['entity_type'], $args['id']); |
|
| 88 | return function ($value, array $args, ResolveInfo $info) use ($resolver) { |
|
| 89 | if (!$entity = $resolver()) { |
|
| 90 | // If there is no entity with this id, add the list cache tags so that the |
|
| 91 | // cache entry is purged whenever a new entity of this type is saved. |
|
| 92 | $pluginDefinition = $this->getPluginDefinition(); |
|
| 93 | $entityType = $this->entityTypeManager->getDefinition($pluginDefinition['entity_type']); |
|
| 94 | $metadata = new CacheableMetadata(); |
|
| 95 | $metadata->addCacheTags($entityType->getListCacheTags()); |
|
| 96 | ||
| 97 | yield new CacheableValue(NULL, [$metadata]); |
|
| 98 | } |
|
| 99 | /** @var \Drupal\Core\Access\AccessResultInterface $access */ |
|
| 100 | else if (($access = $entity->access('view', NULL, TRUE)) && $access->isAllowed()) { |
|
| 101 | if (isset($args['language']) && $args['language'] != $entity->language()->getId()) { |
|
| 102 | $entity = $this->entityRepository->getTranslationFromContext($entity, $args['language']); |
|
| 103 | } |
|
| 104 | ||
| 105 | yield new CacheableValue($entity, [$access]); |
|
| 106 | } |
|
| 107 | else { |
|
| 108 | // If the entity exists but we do not grant access to it, we still want |
|
| 109 | // to have it's cache metadata in the output because future changes to |
|
| 110 | // the entity might affect its visibility for the user. |
|
| 111 | yield new CacheableValue(NULL, [$access]); |
|
| 112 | } |
|
| 113 | }; |
|
| 114 | } |
|
| 115 | ||
| @@ 78-101 (lines=24) @@ | ||
| 75 | $definition = $this->getPluginDefinition(); |
|
| 76 | $storage = $this->entityTypeManager->getStorage($definition['entity_type']); |
|
| 77 | ||
| 78 | if (!$entity = $storage->loadRevision($args['id'])) { |
|
| 79 | // If there is no entity with this id, add the list cache tags so that the |
|
| 80 | // cache entry is purged whenever a new entity of this type is saved. |
|
| 81 | $pluginDefinition = $this->getPluginDefinition(); |
|
| 82 | $entityType = $this->entityTypeManager->getDefinition($pluginDefinition['entity_type']); |
|
| 83 | $metadata = new CacheableMetadata(); |
|
| 84 | $metadata->addCacheTags($entityType->getListCacheTags()); |
|
| 85 | ||
| 86 | yield new CacheableValue(NULL, [$metadata]); |
|
| 87 | } |
|
| 88 | /** @var \Drupal\Core\Access\AccessResultInterface $access */ |
|
| 89 | else if (($access = $entity->access('view', NULL, TRUE)) && $access->isAllowed()) { |
|
| 90 | if (isset($args['language']) && $args['language'] != $entity->language()->getId()) { |
|
| 91 | $entity = $this->entityRepository->getTranslationFromContext($entity, $args['language']); |
|
| 92 | } |
|
| 93 | ||
| 94 | yield new CacheableValue($entity, [$access]); |
|
| 95 | } |
|
| 96 | else { |
|
| 97 | // If the entity exists but we do not grant access to it, we still want |
|
| 98 | // to have it's cache metadata in the output because future changes to |
|
| 99 | // the entity might affect its visibility for the user. |
|
| 100 | yield new CacheableValue(NULL, [$access]); |
|
| 101 | } |
|
| 102 | } |
|
| 103 | ||
| 104 | } |
|