From f4fe495f362d9bdc11937563f006c2dbd48795b0 Mon Sep 17 00:00:00 2001 From: edurenye Date: Mon, 26 Aug 2024 11:31:44 +0200 Subject: [PATCH] chore(dataproducer): suggestions from code review (#1382) --- .../GraphQL/DataProducer/Entity/EntityLabel.php | 11 +++++++---- tests/src/Kernel/DataProducer/EntityTest.php | 4 ---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Plugin/GraphQL/DataProducer/Entity/EntityLabel.php b/src/Plugin/GraphQL/DataProducer/Entity/EntityLabel.php index d80846220..2d7db0759 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/EntityLabel.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/EntityLabel.php @@ -22,7 +22,7 @@ * "entity" = @ContextDefinition("entity", * label = @Translation("Entity") * ), - * "access" = @ContextDefinition("boolean", + * "check_access" = @ContextDefinition("boolean", * label = @Translation("Check access"), * required = FALSE, * default_value = TRUE @@ -41,14 +41,17 @@ class EntityLabel extends DataProducerPluginBase implements DataProducerPluginCa * Resolver. * * @param \Drupal\Core\Entity\EntityInterface $entity - * @param bool $access + * @param bool $check_access * @param \Drupal\Core\Session\AccountInterface|null $accessUser * @param \Drupal\graphql\GraphQL\Execution\FieldContext $context * * @return string|null */ - public function resolve(EntityInterface $entity, bool $access, ?AccountInterface $accessUser, FieldContext $context) { - if ($access) { + public function resolve(EntityInterface $entity, ?bool $check_access, ?AccountInterface $accessUser, FieldContext $context) { + if (is_null($check_access)) { + $check_access = TRUE; + } + if ($check_access) { /** @var \Drupal\Core\Access\AccessResultInterface $accessResult */ $accessResult = $entity->access('view label', $accessUser, TRUE); $context->addCacheableDependency($accessResult); diff --git a/tests/src/Kernel/DataProducer/EntityTest.php b/tests/src/Kernel/DataProducer/EntityTest.php index 16452287e..4bcc11309 100644 --- a/tests/src/Kernel/DataProducer/EntityTest.php +++ b/tests/src/Kernel/DataProducer/EntityTest.php @@ -223,14 +223,10 @@ public function testResolveLabel(): void { $this->assertEquals('Dummy label', $this->executeDataProducer('entity_label', [ 'entity' => $this->entity, - // @todo Remove when https://github.com/drupal-graphql/graphql/issues/1233 is fixed. - 'access' => TRUE, ])); $this->assertNull($this->executeDataProducer('entity_label', [ 'entity' => $this->entity, - // @todo Remove when https://github.com/drupal-graphql/graphql/issues/1233 is fixed. - 'access' => TRUE, ])); }