vendor/pimcore/data-hub/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Objects.php line 72

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectQueryFieldConfigGenerator\Helper;
  15. use GraphQL\Type\Definition\ResolveInfo;
  16. use Pimcore\Bundle\DataHubBundle\GraphQL\ElementDescriptor;
  17. use Pimcore\Bundle\DataHubBundle\GraphQL\Service;
  18. use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait;
  19. use Pimcore\Bundle\DataHubBundle\WorkspaceHelper;
  20. use Pimcore\Model\DataObject\ClassDefinition;
  21. use Pimcore\Model\DataObject\ClassDefinition\Data;
  22. use Pimcore\Model\Element\AbstractElement;
  23. class Objects
  24. {
  25.     use ServiceTrait;
  26.     /**
  27.      * @var Data
  28.      */
  29.     public $fieldDefinition;
  30.     /**
  31.      * @var ClassDefinition
  32.      */
  33.     public $class;
  34.     /**
  35.      * @var string
  36.      */
  37.     public $attribute;
  38.     /**
  39.      * @param Service $graphQlService
  40.      * @param string $attribute
  41.      * @param Data $fieldDefinition
  42.      * @param ClassDefinition $class
  43.      */
  44.     public function __construct(Service $graphQlService$attribute$fieldDefinition$class)
  45.     {
  46.         $this->fieldDefinition $fieldDefinition;
  47.         $this->class $class;
  48.         $this->attribute $attribute;
  49.         $this->setGraphQLService($graphQlService);
  50.     }
  51.     /**
  52.      * @param mixed $value
  53.      * @param array $args
  54.      * @param array $context
  55.      * @param ResolveInfo|null $resolveInfo
  56.      *
  57.      * @return array|null
  58.      *
  59.      * @throws \Exception
  60.      */
  61.     public function resolve($value null$args = [], $context = [], ResolveInfo $resolveInfo null)
  62.     {
  63.         $relations \Pimcore\Bundle\DataHubBundle\GraphQL\Service::resolveValue($value$this->fieldDefinition$this->attribute$args);
  64.         if ($relations) {
  65.             $result = [];
  66.             /** @var AbstractElement $relation */
  67.             foreach ($relations as $relation) {
  68.                 if (!WorkspaceHelper::checkPermission($relation'read')) {
  69.                     continue;
  70.                 }
  71.                 $data = new ElementDescriptor($relation);
  72.                 $this->getGraphQlService()->extractData($data$relation$args$context$resolveInfo);
  73.                 $result[] = $data;
  74.             }
  75.             return $result;
  76.         }
  77.         return null;
  78.     }
  79. }