vendor/pimcore/data-hub/src/GraphQL/DataObjectQueryFieldConfigGenerator/Helper/Href.php line 73

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\ElementInterface;
  23. class Href
  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->attribute $attribute;
  47.         $this->fieldDefinition $fieldDefinition;
  48.         $this->class $class;
  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 ElementDescriptor|null
  58.      *
  59.      * @throws \Exception
  60.      */
  61.     public function resolve($value null$args = [], $context = [], ResolveInfo $resolveInfo null)
  62.     {
  63.         $relation \Pimcore\Bundle\DataHubBundle\GraphQL\Service::resolveValue($value$this->fieldDefinition$this->attribute$args);
  64.         if ($relation instanceof ElementInterface) {
  65.             if (!WorkspaceHelper::checkPermission($relation'read')) {
  66.                 return null;
  67.             }
  68.             $data = new ElementDescriptor($relation);
  69.             $this->getGraphQlService()->extractData($data$relation$args$context$resolveInfo);
  70.             return $data;
  71.         }
  72.         return null;
  73.     }
  74. }