From b01c848def4f614cde20f6dffac3dea16e4cf253 Mon Sep 17 00:00:00 2001 From: Jason Hughes Date: Thu, 26 Nov 2020 21:56:50 +1000 Subject: [PATCH] Add image ID to ImageDerivative return for issue 1120 Change field name to id Make plugin configurable to return additional properties Remove id from return Add ID back to return --- .../Entity/Fields/Image/ImageDerivative.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php index 955fd8173..91051e95a 100644 --- a/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php +++ b/src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php @@ -26,6 +26,9 @@ * ), * "style" = @ContextDefinition("string", * label = @Translation("Image style") + * ), + * "additional_properties" = @ContextDefinition("list", + * label = @Translation("Additional properties") * ) * } * ) @@ -85,7 +88,7 @@ public function __construct( * * @return mixed */ - public function resolve(FileInterface $entity = NULL, $style, RefinableCacheableDependencyInterface $metadata) { + public function resolve(FileInterface $entity = NULL, $style, array $additional_properties = [], RefinableCacheableDependencyInterface $metadata) { // Return if we dont have an entity. if (!$entity) { return NULL; @@ -129,11 +132,18 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable $metadata->addCacheableDependency($context->pop()); } - return [ + $return = [ + 'id' => $entity->id(), 'url' => $url, 'width' => $dimensions['width'], 'height' => $dimensions['height'], ]; + + foreach($additional_properties as $property) { + $return[$property] = $entity->get($property)->value; + } + + return $return; } return NULL;