protected function EntityRevisionById::resolveValues in GraphQL 8.3
Retrieve the list of field values.
Always returns a list of field values. Even for single value fields. Single/multi field handling is responsibility of the base class.
Parameters
mixed $value: The current object value.
array $args: Field arguments.
$context: The resolve context.
\GraphQL\Type\Definition\ResolveInfo $info: The resolve info object.
Return value
\Generator The value generator.
Overrides FieldPluginBase::resolveValues
File
- modules/
graphql_core/ src/ Plugin/ GraphQL/ Fields/ Entity/ EntityRevisionById.php, line 87
Class
- EntityRevisionById
- Plugin annotation @GraphQLField( id = "entity_revision_by_id", secure = true, arguments = { "id" = "String!" }, contextual_arguments = {"language"}, deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityRevisionByIdDeriver" )
Namespace
Drupal\graphql_core\Plugin\GraphQL\Fields\EntityCode
protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
$definition = $this
->getPluginDefinition();
$storage = $this->entityTypeManager
->getStorage($definition['entity_type']);
if (!($entity = $storage
->loadRevision($args['id']))) {
// If there is no entity with this id, add the list cache tags so that the
// cache entry is purged whenever a new entity of this type is saved.
$pluginDefinition = $this
->getPluginDefinition();
$entityType = $this->entityTypeManager
->getDefinition($pluginDefinition['entity_type']);
$metadata = new CacheableMetadata();
$metadata
->addCacheTags($entityType
->getListCacheTags());
(yield new CacheableValue(NULL, [
$metadata,
]));
}
else {
if (($access = $entity
->access('view', NULL, TRUE)) && $access
->isAllowed()) {
if ($entity instanceof TranslatableInterface && isset($args['language']) && $args['language'] != $entity
->language()
->getId() && $entity
->isTranslatable()) {
if ($entity
->hasTranslation($args['language'])) {
$entity = $entity
->getTranslation($args['language']);
}
}
(yield new CacheableValue($entity, [
$access,
]));
}
else {
// If the entity exists but we do not grant access to it, we still want
// to have it's cache metadata in the output because future changes to
// the entity might affect its visibility for the user.
(yield new CacheableValue(NULL, [
$access,
]));
}
}
}