Skip to content

Commit bb2f0c0

Browse files
authored
fix(DataProducer): Fix missing cacheability bubble up on entity translations data producer (#1353)
1 parent db158cc commit bb2f0c0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\Core\Entity\TranslatableInterface;
99
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
1010
use Drupal\Core\Session\AccountInterface;
11+
use Drupal\graphql\GraphQL\Execution\FieldContext;
1112
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
1213
use Symfony\Component\DependencyInjection\ContainerInterface;
1314

@@ -97,10 +98,11 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition,
9798
* @param bool|null $access
9899
* @param \Drupal\Core\Session\AccountInterface|null $accessUser
99100
* @param string|null $accessOperation
101+
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
100102
*
101103
* @return \Drupal\Core\Entity\EntityInterface|null
102104
*/
103-
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) {
105+
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
104106
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
105107
$entity = $entity->getTranslation($language);
106108
$entity->addCacheContexts(["static:language:{$language}"]);
@@ -109,6 +111,7 @@ public function resolve(EntityInterface $entity, $language, ?bool $access, ?Acco
109111
if ($access) {
110112
/** @var \Drupal\Core\Access\AccessResultInterface $accessResult */
111113
$accessResult = $entity->access($accessOperation, $accessUser, TRUE);
114+
$context->addCacheableDependency($accessResult);
112115
if (!$accessResult->isAllowed()) {
113116
return NULL;
114117
}

src/Plugin/GraphQL/DataProducer/Entity/EntityTranslations.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Drupal\Core\Language\LanguageInterface;
1010
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
1111
use Drupal\Core\Session\AccountInterface;
12+
use Drupal\graphql\GraphQL\Execution\FieldContext;
1213
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
1314
use Symfony\Component\DependencyInjection\ContainerInterface;
1415

@@ -96,20 +97,22 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition,
9697
* @param bool|null $access
9798
* @param \Drupal\Core\Session\AccountInterface|null $accessUser
9899
* @param string|null $accessOperation
100+
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
99101
*
100102
* @return array|null
101103
*/
102-
public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) {
104+
public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
103105
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
104106
$languages = $entity->getTranslationLanguages();
105107

106-
return array_map(function (LanguageInterface $language) use ($entity, $access, $accessOperation, $accessUser) {
108+
return array_map(function (LanguageInterface $language) use ($entity, $access, $accessOperation, $accessUser, $context) {
107109
$langcode = $language->getId();
108110
$entity = $entity->getTranslation($langcode);
109111
$entity->addCacheContexts(["static:language:{$langcode}"]);
110112
if ($access) {
111113
/** @var \Drupal\Core\Access\AccessResultInterface $accessResult */
112114
$accessResult = $entity->access($accessOperation, $accessUser, TRUE);
115+
$context->addCacheableDependency($accessResult);
113116
if (!$accessResult->isAllowed()) {
114117
return NULL;
115118
}

0 commit comments

Comments
 (0)