Skip to content

Commit

Permalink
fix(DataProducer): Fix missing cacheability bubble up on entity trans…
Browse files Browse the repository at this point in the history
…lations data producer
  • Loading branch information
mxr576 committed Aug 31, 2023
1 parent bf9dea3 commit 0ea4415
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Plugin/GraphQL/DataProducer/Entity/EntityTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Entity\TranslatableInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -97,10 +98,11 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition,
* @param bool|null $access
* @param \Drupal\Core\Session\AccountInterface|null $accessUser
* @param string|null $accessOperation
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
*
* @return \Drupal\Core\Entity\EntityInterface|null
*/
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) {
public function resolve(EntityInterface $entity, $language, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
$entity = $entity->getTranslation($language);
$entity->addCacheContexts(["static:language:{$language}"]);
Expand All @@ -109,6 +111,7 @@ public function resolve(EntityInterface $entity, $language, ?bool $access, ?Acco
if ($access) {
/** @var \Drupal\Core\Access\AccessResultInterface $accessResult */
$accessResult = $entity->access($accessOperation, $accessUser, TRUE);
$context->addCacheableDependency($accessResult);
if (!$accessResult->isAllowed()) {
return NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -96,10 +97,11 @@ public function __construct(array $configuration, $pluginId, $pluginDefinition,
* @param bool|null $access
* @param \Drupal\Core\Session\AccountInterface|null $accessUser
* @param string|null $accessOperation
* @param \Drupal\graphql\GraphQL\Execution\FieldContext $context
*
* @return array|null
*/
public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation) {
public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterface $accessUser, ?string $accessOperation, FieldContext $context) {
if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
$languages = $entity->getTranslationLanguages();

Expand All @@ -110,6 +112,7 @@ public function resolve(EntityInterface $entity, ?bool $access, ?AccountInterfac
if ($access) {
/** @var \Drupal\Core\Access\AccessResultInterface $accessResult */
$accessResult = $entity->access($accessOperation, $accessUser, TRUE);
$context->addCacheableDependency($accessResult);

Check failure on line 115 in src/Plugin/GraphQL/DataProducer/Entity/EntityTranslations.php

View workflow job for this annotation

GitHub Actions / Drupal 10.0.x (PHP 8.2)

Undefined variable: $context
if (!$accessResult->isAllowed()) {
return NULL;
}
Expand Down

0 comments on commit 0ea4415

Please sign in to comment.