diff --git a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php new file mode 100644 index 00000000..7e221735 --- /dev/null +++ b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php @@ -0,0 +1,85 @@ +attribute = $attribute; + $this->fieldDefinition = $fieldDefinition; + $this->class = $class; + + $this->setGraphQLService($graphQlService); + } + + /** + * @param null $value + * @param array $args + * @param array $context + * @param ResolveInfo|null $resolveInfo + * + * @return array|null + * + * @throws \Exception + */ + public function resolve($value = null, $args = [], $context = [], ResolveInfo $resolveInfo = null) + { + $relation = \Pimcore\Bundle\DataHubBundle\GraphQL\Service::resolveValue($value, $this->fieldDefinition, $this->attribute, $args); + + if ($relation instanceof Asset) { + if (!WorkspaceHelper::checkPermission($relation, 'read')) { + return null; + } + + $data = new ElementDescriptor($relation); + $this->getGraphQlService()->extractData($data, $relation, $args, $context, $resolveInfo); + + return $data; + } + } +} diff --git a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php index 7390eee0..cf628fa2 100644 --- a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php +++ b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php @@ -15,6 +15,21 @@ namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectQueryFieldConfigGenerator; +use Pimcore\Model\DataObject\ClassDefinition\Data; + class Image extends AssetBase { + /** + * @param $attribute + * @param Data $fieldDefinition + * @param $class + * + * @return \Closure + */ + public function getResolver($attribute, $fieldDefinition, $class) + { + $resolver = new Helper\Image($this->getGraphQlService(), $attribute, $fieldDefinition, $class); + + return [$resolver, 'resolve']; + } }