Code Duplication    Length = 13-15 lines in 2 locations

modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityById.php 1 location

@@ 95-109 (lines=15) @@
92
        $entityType = $this->entityTypeManager->getDefinition($pluginDefinition['entity_type']);
93
        yield (new CacheableValue(NULL))->addCacheTags($entityType->getListCacheTags());
94
      }
95
      else {
96
        /** @var \Drupal\Core\Entity\EntityInterface $entity */
97
        $access = $entity->access('view', NULL, TRUE);
98
99
        if ($access->isAllowed()) {
100
          if (isset($args['language']) && $args['language'] != $entity->language()->getId()) {
101
            $entity = $this->entityRepository->getTranslationFromContext($entity, $args['language']);
102
          }
103
104
          yield $entity->addCacheableDependency($access);
105
        }
106
        else {
107
          yield new CacheableValue(NULL, [$access]);
108
        }
109
      }
110
    };
111
  }
112

modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityRevisionById.php 1 location

@@ 89-101 (lines=13) @@
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
}