From a648e3abd53d481ca48250f29c99c431e97918db Mon Sep 17 00:00:00 2001 From: weisswurstkanone Date: Tue, 8 Jun 2021 14:55:29 +0200 Subject: [PATCH 1/2] Query assets by language not working #369 --- .../Helper/Image.php | 86 +++++++++++++++++++ .../Image.php | 16 ++++ 2 files changed, 102 insertions(+) create mode 100644 src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php diff --git a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php new file mode 100644 index 00000000..f46b452b --- /dev/null +++ b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php @@ -0,0 +1,86 @@ +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..86a500f3 100644 --- a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php +++ b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php @@ -15,6 +15,22 @@ 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']; + } } From d601fae6141bc5035543bf72ace6dfdac8ed6ddd Mon Sep 17 00:00:00 2001 From: weisswurstkanone Date: Tue, 8 Jun 2021 12:57:35 +0000 Subject: [PATCH 2/2] Apply php-cs-fixer changes --- src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php | 1 - src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php index f46b452b..7e221735 100644 --- a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php +++ b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php @@ -20,7 +20,6 @@ use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait; use Pimcore\Bundle\DataHubBundle\WorkspaceHelper; use Pimcore\Model\Asset; -use Pimcore\Model\Element\ElementInterface; class Image { diff --git a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php index 86a500f3..cf628fa2 100644 --- a/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php +++ b/src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php @@ -19,7 +19,6 @@ class Image extends AssetBase { - /** * @param $attribute * @param Data $fieldDefinition