Skip to content

Commit

Permalink
Merge pull request #370 from pimcore/image_rel
Browse files Browse the repository at this point in the history
Query assets by language not working
  • Loading branch information
weisswurstkanone authored Jun 8, 2021
2 parents 21ad09c + d601fae commit 9977b93
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectQueryFieldConfigGenerator\Helper;

use GraphQL\Type\Definition\ResolveInfo;
use Pimcore\Bundle\DataHubBundle\GraphQL\ElementDescriptor;
use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait;
use Pimcore\Bundle\DataHubBundle\WorkspaceHelper;
use Pimcore\Model\Asset;

class Image
{
use ServiceTrait;

/**
* @var
*/
public $fieldDefinition;

/**
* @var
*/
public $class;

/**
* @var
*/
public $attribute;

/**
* Href constructor.
*
* @param \Pimcore\Bundle\DataHubBundle\GraphQL\Service $graphQlService
* @param $attribute
* @param $fieldDefinition
* @param $class
*/
public function __construct(\Pimcore\Bundle\DataHubBundle\GraphQL\Service $graphQlService, $attribute, $fieldDefinition, $class)
{
$this->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;
}
}
}
15 changes: 15 additions & 0 deletions src/GraphQL/DataObjectQueryFieldConfigGenerator/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}

0 comments on commit 9977b93

Please sign in to comment.