vendor/pimcore/data-hub/src/GraphQL/Service.php line 445

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. declare(strict_types=1);
  15. /**
  16.  * Pimcore
  17.  *
  18.  * This source file is available under two different licenses:
  19.  * - GNU General Public License version 3 (GPLv3)
  20.  * - Pimcore Commercial License (PCL)
  21.  * Full copyright and license information is available in
  22.  * LICENSE.md which is distributed with this source code.
  23.  *
  24.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  25.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  26.  */
  27. namespace Pimcore\Bundle\DataHubBundle\GraphQL;
  28. use GraphQL\Type\Definition\ResolveInfo;
  29. use Pimcore\Bundle\DataHubBundle\Configuration;
  30. use Pimcore\Bundle\DataHubBundle\GraphQL\Exception\ClientSafeException;
  31. use Pimcore\Bundle\DataHubBundle\GraphQL\FieldHelper\AssetFieldHelper;
  32. use Pimcore\Bundle\DataHubBundle\GraphQL\FieldHelper\DataObjectFieldHelper;
  33. use Pimcore\Bundle\DataHubBundle\GraphQL\FieldHelper\DocumentFieldHelper;
  34. use Pimcore\Bundle\DataHubBundle\GraphQL\Query\Operator\Factory\OperatorFactoryInterface;
  35. use Pimcore\Bundle\DataHubBundle\GraphQL\Query\Value\DefaultValue;
  36. use Pimcore\Bundle\DataHubBundle\PimcoreDataHubBundle;
  37. use Pimcore\Cache\Runtime;
  38. use Pimcore\Localization\LocaleServiceInterface;
  39. use Pimcore\Model\Asset;
  40. use Pimcore\Model\DataObject\AbstractObject;
  41. use Pimcore\Model\DataObject\ClassDefinition;
  42. use Pimcore\Model\DataObject\ClassDefinition\Data;
  43. use Pimcore\Model\DataObject\Concrete;
  44. use Pimcore\Model\DataObject\Objectbrick\Data\AbstractData;
  45. use Pimcore\Model\DataObject\Objectbrick\Definition;
  46. use Pimcore\Model\Document;
  47. use Pimcore\Model\Element\AbstractElement;
  48. use Pimcore\Model\Factory;
  49. use Pimcore\Translation\Translator;
  50. use Psr\Container\ContainerInterface;
  51. class Service
  52. {
  53.     /***
  54.      * @var ContainerInterface
  55.      */
  56.     protected $dataObjectQueryTypeGeneratorFactories;
  57.     /***
  58.      * @var ContainerInterface
  59.      */
  60.     protected $dataObjectMutationTypeGeneratorFactories;
  61.     /**
  62.      * @var ContainerInterface
  63.      */
  64.     protected $dataObjectQueryOperatorFactories;
  65.     /**
  66.      * @var ContainerInterface
  67.      */
  68.     protected $documentElementQueryTypeGeneratorFactories;
  69.     /**
  70.      * @var ContainerInterface
  71.      */
  72.     protected $documentElementMutationTypeGeneratorFactories;
  73.     /**
  74.      * @var ContainerInterface
  75.      */
  76.     protected $dataObjectMutationOperatorFactories;
  77.     /**
  78.      * @var ContainerInterface
  79.      */
  80.     protected $generalTypeGeneratorFactories;
  81.     /**
  82.      * @var ContainerInterface
  83.      */
  84.     protected $assetTypeGeneratorFactories;
  85.     /**
  86.      * @var ContainerInterface
  87.      */
  88.     protected $csFeatureTypeGeneratorFactories;
  89.     /**
  90.      * @var array
  91.      */
  92.     protected $supportedDataObjectQueryDataTypes;
  93.     /**
  94.      * @var array
  95.      */
  96.     protected $supportedDocumentElementQueryDataTypes;
  97.     /**
  98.      * @var array
  99.      */
  100.     protected $supportedDocumentElementMutationDataTypes;
  101.     /**
  102.      * @var array
  103.      */
  104.     protected $supportedCsFeatureQueryDataTypes;
  105.     /**
  106.      * @var array
  107.      */
  108.     protected $supportedDataObjectMutationDataTypes;
  109.     /**
  110.      * @var DataObjectFieldHelper
  111.      */
  112.     protected $objectFieldHelper;
  113.     /**
  114.      * @var AssetFieldHelper
  115.      */
  116.     protected $assetFieldHelper;
  117.     /**
  118.      * @var documentFieldHelper
  119.      */
  120.     protected $documentFieldHelper;
  121.     /**
  122.      * @var LocaleServiceInterface
  123.      */
  124.     protected $localeService;
  125.     /**
  126.      * @var Translator
  127.      */
  128.     protected $translator;
  129.     /**
  130.      * @var Factory
  131.      */
  132.     protected $modelFactory;
  133.     /**
  134.      * @var array
  135.      */
  136.     protected $generalTypes = [];
  137.     /**
  138.      * @var array
  139.      */
  140.     protected $assetDataTypes = [];
  141.     /**
  142.      * @var array
  143.      */
  144.     protected $documentDataTypes = [];
  145.     /**
  146.      * @var array
  147.      */
  148.     protected $propertyDataTypes = [];
  149.     /**
  150.      * @var array
  151.      */
  152.     protected $classificationStoreDataTypes = [];
  153.     /**
  154.      * @var array
  155.      */
  156.     protected $dataObjectDataTypes = [];
  157.     protected $tagManagerListener;
  158.     /**
  159.      * Service constructor.
  160.      *
  161.      * @param AssetFieldHelper $assetFieldHelper
  162.      * @param DocumentFieldHelper $documentFieldHelper
  163.      * @param DataObjectFieldHelper $objectFieldHelper
  164.      * @param LocaleServiceInterface $localeService
  165.      * @param Factory $modelFactory
  166.      * @param Translator $translator
  167.      * @param ContainerInterface $dataObjectQueryTypeGeneratorFactories
  168.      * @param ContainerInterface $dataObjectQueryOperatorFactories
  169.      * @param ContainerInterface $dataObjectMutationTypeGeneratorFactories
  170.      * @param ContainerInterface $dataObjectMutationOperatorFactories
  171.      * @param ContainerInterface $documentElementQueryTypeGeneratorFactories
  172.      * @param ContainerInterface $documentElementMutationTypeGeneratorFactories
  173.      * @param ContainerInterface $generalTypeGeneratorFactories
  174.      * @param ContainerInterface $assetTypeGeneratorFactories
  175.      * @param ContainerInterface $csFeatureTypeGeneratorFactories
  176.      */
  177.     public function __construct(
  178.         AssetFieldHelper $assetFieldHelper,
  179.         DocumentFieldHelper $documentFieldHelper,
  180.         DataObjectFieldHelper $objectFieldHelper,
  181.         LocaleServiceInterface $localeService,
  182.         Factory $modelFactory,
  183.         Translator $translator,
  184.         ContainerInterface $dataObjectQueryTypeGeneratorFactories,
  185.         ContainerInterface $dataObjectQueryOperatorFactories,
  186.         ContainerInterface $dataObjectMutationTypeGeneratorFactories,
  187.         ContainerInterface $dataObjectMutationOperatorFactories,
  188.         ContainerInterface $documentElementQueryTypeGeneratorFactories,
  189.         ContainerInterface $documentElementMutationTypeGeneratorFactories,
  190.         ContainerInterface $generalTypeGeneratorFactories,
  191.         ContainerInterface $assetTypeGeneratorFactories,
  192.         ContainerInterface $csFeatureTypeGeneratorFactories
  193.     ) {
  194.         $this->assetFieldHelper $assetFieldHelper;
  195.         $this->documentFieldHelper $documentFieldHelper;
  196.         $this->objectFieldHelper $objectFieldHelper;
  197.         $this->localeService $localeService;
  198.         $this->modelFactory $modelFactory;
  199.         $this->translator $translator;
  200.         $this->dataObjectQueryTypeGeneratorFactories $dataObjectQueryTypeGeneratorFactories;
  201.         $this->dataObjectQueryOperatorFactories $dataObjectQueryOperatorFactories;
  202.         $this->dataObjectMutationTypeGeneratorFactories $dataObjectMutationTypeGeneratorFactories;
  203.         $this->dataObjectMutationOperatorFactories $dataObjectMutationOperatorFactories;
  204.         $this->documentElementQueryTypeGeneratorFactories $documentElementQueryTypeGeneratorFactories//TODO rename this to query
  205.         $this->documentElementMutationGeneratorFactories $documentElementMutationTypeGeneratorFactories;
  206.         $this->generalTypeGeneratorFactories $generalTypeGeneratorFactories;
  207.         $this->assetTypeGeneratorFactories $assetTypeGeneratorFactories;
  208.         $this->csFeatureTypeGeneratorFactories $csFeatureTypeGeneratorFactories;
  209.     }
  210.     /**
  211.      * @param $attribute
  212.      * @param $typeName
  213.      * @param Data|null $fieldDefinition
  214.      * @param ClassDefinition|\Pimcore\Model\DataObject\Fieldcollection\Definition|null $class
  215.      * @param null $container
  216.      *
  217.      * @return mixed
  218.      */
  219.     public function buildDataObjectQueryDataConfig($attribute$typeName$fieldDefinition null$class null$container null)
  220.     {
  221.         /** @var DataObjectQueryFieldConfigGeneratorInterface $factory */
  222.         $factory $this->dataObjectQueryTypeGeneratorFactories->get('typegenerator_dataobjectquerydatatype_' $typeName);
  223.         $result $factory->getGraphQlFieldConfig($attribute$fieldDefinition$class$container);
  224.         return $result;
  225.     }
  226.     /**
  227.      * @param $nodeDef
  228.      * @param $typeName
  229.      * @param ClassDefinition|\Pimcore\Model\DataObject\Fieldcollection\Definition $class
  230.      * @param null $container
  231.      *
  232.      * @return mixed
  233.      */
  234.     public function buildDataObjectMutationDataConfig($nodeDef$class null$container null)
  235.     {
  236.         /** @var DataObjectMutationFieldConfigGeneratorInterface $factory */
  237.         $typeName $nodeDef['attributes']['dataType'];
  238.         $factory $this->dataObjectMutationTypeGeneratorFactories->get('typegenerator_dataobjectmutationdatatype_' $typeName);
  239.         $result $factory->getGraphQlMutationFieldConfig($nodeDef$class$container);
  240.         return $result;
  241.     }
  242.     /**
  243.      * @param $name
  244.      * @param $attribute
  245.      * @param Data|null $fieldDefinition
  246.      * @param ClassDefinition|null $class
  247.      * @param null $container
  248.      *
  249.      * @return mixed
  250.      */
  251.     public function buildDataObjectDataQueryResolver($attributeData $fieldDefinition nullClassDefinition $class null)
  252.     {
  253.         $name $fieldDefinition->getFieldtype();
  254.         /** @var DataObjectQueryFieldConfigGeneratorInterface $factory */
  255.         $factory $this->dataObjectQueryTypeGeneratorFactories->get('typegenerator_dataobjectquerydatatype_' $name);
  256.         $resolver $factory->getResolver($attribute$fieldDefinition$class);
  257.         return $resolver;
  258.     }
  259.     /**
  260.      * @param $name
  261.      * @param Data|null $fieldDefinition
  262.      * @param ClassDefinition|null $class
  263.      * @param null $container
  264.      *
  265.      * @return mixed
  266.      */
  267.     public function buildDataObjectDataQueryType(Data $fieldDefinition nullClassDefinition $class null$container null)
  268.     {
  269.         $name $fieldDefinition->getFieldtype();
  270.         /** @var DataObjectQueryFieldConfigGeneratorInterface $factory */
  271.         $factory $this->dataObjectQueryTypeGeneratorFactories->get('typegenerator_dataobjectquerydatatype_' $name);
  272.         $result $factory->getFieldType($fieldDefinition$class$container);
  273.         return $result;
  274.     }
  275.     /**
  276.      * @param $elementName
  277.      *
  278.      * @return mixed
  279.      */
  280.     public function buildDocumentElementDataQueryType($elementName)
  281.     {
  282.         $factory $this->documentElementQueryTypeGeneratorFactories->get('typegenerator_documentelementquerydatatype_' $elementName);
  283.         $result $factory->getFieldType();
  284.         return $result;
  285.     }
  286.     /**
  287.      * @param $elementName
  288.      *
  289.      * @return mixed
  290.      */
  291.     public function buildDocumentElementDataMutationType($elementName)
  292.     {
  293.         $factory $this->documentElementMutationGeneratorFactories->get('typegenerator_documentelementmutationdatatype_' $elementName);
  294.         $result $factory->getDocumentElementMutationFieldConfig();
  295.         return $result;
  296.     }
  297.     /**
  298.      * @param $elementName
  299.      *
  300.      * @return mixed
  301.      */
  302.     public function buildCsFeatureDataQueryType($elementName)
  303.     {
  304.         $factory $this->csFeatureTypeGeneratorFactories->get('typegenerator_csfeaturequerydatatype_' $elementName);
  305.         $result $factory->getFieldType();
  306.         return $result;
  307.     }
  308.     /**
  309.      * @param $typeName
  310.      *
  311.      * @return bool
  312.      */
  313.     public function supportsDataObjectQueryDataType($typeName)
  314.     {
  315.         return $this->dataObjectQueryTypeGeneratorFactories->has('typegenerator_dataobjectquerydatatype_' $typeName);
  316.     }
  317.     /**
  318.      * @param $typeName
  319.      *
  320.      * @return bool
  321.      */
  322.     public function supportsDataObjectMutationDataType($typeName)
  323.     {
  324.         return $this->dataObjectMutationTypeGeneratorFactories->has('typegenerator_dataobjectmutationdatatype_' $typeName);
  325.     }
  326.     /**
  327.      * @param $typeName
  328.      * @param $nodeDef
  329.      * @param Data|null $fieldDefinition
  330.      * @param ClassDefinition|null $class
  331.      * @param null $container
  332.      *
  333.      * @return mixed
  334.      */
  335.     public function buildDataObjectQueryOperatorConfig($typeName$nodeDefClassDefinition $class null$container null$params = [])
  336.     {
  337.         $typeName strtolower($typeName);
  338.         /** @var DataObjectQueryFieldConfigGeneratorInterface $factory */
  339.         $factory $this->dataObjectQueryTypeGeneratorFactories->get('typegenerator_queryoperator_' $typeName);
  340.         $result $factory->getGraphQlQueryOperatorConfig($typeName$nodeDef$class$container$params);
  341.         return $result;
  342.     }
  343.     /**
  344.      * @param $typeName
  345.      * @param $nodeDef
  346.      * @param ClassDefinition|null $class
  347.      * @param null $container
  348.      * @param array $params
  349.      *
  350.      * @return mixed
  351.      *
  352.      * @throws \Exception
  353.      */
  354.     public function buildDataObjectMutationOperatorConfig($typeName$nodeDefClassDefinition $class null$container null$params = [])
  355.     {
  356.         $typeName strtolower($typeName);
  357.         // $factory = $this->mutationTypeGeneratorFactories->get('typegenerator_mutationoperator_' . $typeName);
  358.         $factory $this->dataObjectMutationOperatorFactories->get($typeName);
  359.         $context Runtime::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY);
  360.         $configGenerator $factory->build($nodeDef['attributes'], $context);
  361.         $result $configGenerator->getGraphQlMutationOperatorConfig($nodeDef$class$container$params);
  362.         return $result;
  363.     }
  364.     /**
  365.      * @param $mode
  366.      * @param $typeName
  367.      * @param $nodeDef
  368.      * @param ClassDefinition|null $class
  369.      * @param null $container
  370.      * @param array $params
  371.      *
  372.      * @return mixed
  373.      */
  374.     public function buildDataObjectOperatorQueryType($mode$typeName$nodeDefClassDefinition $class null$container null$params = [])
  375.     {
  376.         $typeName strtolower($typeName);
  377.         /** @var DataObjectQueryFieldConfigGeneratorInterface $factory */
  378.         $factory $this->dataObjectQueryTypeGeneratorFactories->get('typegenerator_operator_' $typeName);
  379.         $result $factory->getGraphQlOperatorConfig($mode$typeName$nodeDef$class$container$params);
  380.         return $result;
  381.     }
  382.     /**
  383.      * @param $typeName
  384.      *
  385.      * @return mixed
  386.      *
  387.      * @throws \Exception
  388.      */
  389.     public function buildGeneralType($typeName)
  390.     {
  391.         $factory $this->generalTypeGeneratorFactories->get($typeName);
  392.         $result $factory->build();
  393.         return $result;
  394.     }
  395.     /**
  396.      * @param $typeName
  397.      *
  398.      * @return mixed
  399.      *
  400.      * @throws \Exception
  401.      */
  402.     public function buildAssetType($typeName)
  403.     {
  404.         $factory $this->assetTypeGeneratorFactories->get($typeName);
  405.         $result $factory->build();
  406.         return $result;
  407.     }
  408.     /**
  409.      * @param $typeName
  410.      * @param $attributes
  411.      * @param Data|null $fieldDefinition
  412.      * @param ClassDefinition|null $class
  413.      * @param null $container
  414.      *
  415.      * @return mixed
  416.      */
  417.     public function buildQueryOperator($typeName$attributes nullClassDefinition $class null$container null)
  418.     {
  419.         $typeName strtolower($typeName);
  420.         /** @var OperatorFactoryInterface $factory */
  421.         $factory $this->dataObjectQueryOperatorFactories->get($typeName);
  422.         $context Runtime::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY);
  423.         $result $factory->build($attributes$context);
  424.         return $result;
  425.     }
  426.     /**
  427.      * @param $nodeConfig
  428.      *
  429.      * @return mixed|DefaultValue
  430.      *
  431.      * @throws \Exception
  432.      */
  433.     public function buildValueResolverFromAttributes($nodeConfig)
  434.     {
  435.         $attributes $nodeConfig['attributes'];
  436.         if ($nodeConfig['isOperator']) {
  437.             $class $attributes['class'];
  438.             $operatorImpl $this->buildQueryOperator($class$attributes);
  439.             return $operatorImpl;
  440.         } else {
  441.             $context Runtime::get(PimcoreDataHubBundle::RUNTIME_CONTEXT_KEY);
  442.             $operatorImpl = new DefaultValue($attributes$context);
  443.             $operatorImpl->setGraphQlService($this);
  444.             return $operatorImpl;
  445.         }
  446.     }
  447.     /**
  448.      * @return array
  449.      */
  450.     public function getSupportedDataObjectQueryDataTypes()
  451.     {
  452.         return $this->supportedDataObjectQueryDataTypes;
  453.     }
  454.     /**
  455.      * @param $supportedDocumentElementQueryDataTypes
  456.      */
  457.     public function setSupportedDocumentElementQueryDataTypes($supportedDocumentElementQueryDataTypes)
  458.     {
  459.         $this->supportedDocumentElementQueryDataTypes $supportedDocumentElementQueryDataTypes;
  460.     }
  461.     /**
  462.      * @param $supportedDocumentElementMutationDataTypes
  463.      */
  464.     public function setSupportedDocumentElementMutationDataTypes($supportedDocumentElementMutationDataTypes)
  465.     {
  466.         $this->supportedDocumentElementMutationDataTypes $supportedDocumentElementMutationDataTypes;
  467.     }
  468.     /**
  469.      * @param $supportedCsFeatureQueryDataTypes
  470.      */
  471.     public function setSupportedCsFeatureQueryDataTypes($supportedCsFeatureQueryDataTypes)
  472.     {
  473.         $this->supportedCsFeatureQueryDataTypes $supportedCsFeatureQueryDataTypes;
  474.     }
  475.     /**
  476.      * @param array $generalTypes
  477.      */
  478.     public function setSupportedGeneralTypes($generalTypes)
  479.     {
  480.         $this->generalTypes $generalTypes;
  481.     }
  482.     /**
  483.      * @return array
  484.      */
  485.     public function getSupportedDocumentElementQueryDataTypes()
  486.     {
  487.         return $this->supportedDocumentElementQueryDataTypes;
  488.     }
  489.     /**
  490.      * @return array
  491.      */
  492.     public function getSupportedDocumentElementMutationDataTypes()
  493.     {
  494.         return $this->supportedDocumentElementMutationDataTypes;
  495.     }
  496.     /**
  497.      * @return array
  498.      */
  499.     public function getSupportedCsFeatureQueryDataTypes()
  500.     {
  501.         return $this->supportedCsFeatureQueryDataTypes;
  502.     }
  503.     /**
  504.      * @param $supportedDataObjectQueryDataTypes
  505.      */
  506.     public function setSupportedDataObjectQueryDataTypes($supportedDataObjectQueryDataTypes)
  507.     {
  508.         $this->supportedDataObjectQueryDataTypes $supportedDataObjectQueryDataTypes;
  509.     }
  510.     /**
  511.      * @return array
  512.      */
  513.     public function getSupportedDataObjectMutationDataTypes(): array
  514.     {
  515.         return $this->supportedDataObjectMutationDataTypes;
  516.     }
  517.     /**
  518.      * @param array $supportedDataObjectMutationDataTypes
  519.      */
  520.     public function setSupportedDataObjectMutationDataTypes(array $supportedDataObjectMutationDataTypes): void
  521.     {
  522.         $this->supportedDataObjectMutationDataTypes $supportedDataObjectMutationDataTypes;
  523.     }
  524.     /**
  525.      * @param $value
  526.      *
  527.      * @return mixed
  528.      */
  529.     public function getElementFromArrayObject($value)
  530.     {
  531.         if ($value instanceof \ArrayObject) {
  532.             $value $value->getArrayCopy();
  533.             if (isset($value['__elementType'])) {
  534.                 $value \Pimcore\Model\Element\Service::getElementById($value['__elementType'], $value['id']);
  535.             }
  536.         }
  537.         return $value;
  538.     }
  539.     /**
  540.      * @return AssetFieldHelper
  541.      */
  542.     public function getAssetFieldHelper()
  543.     {
  544.         return $this->assetFieldHelper;
  545.     }
  546.     /**
  547.      * @return DocumentFieldHelper
  548.      */
  549.     public function getDocumentFieldHelper()
  550.     {
  551.         return $this->documentFieldHelper;
  552.     }
  553.     /**
  554.      * @return DataObjectFieldHelper
  555.      */
  556.     public function getObjectFieldHelper()
  557.     {
  558.         return $this->objectFieldHelper;
  559.     }
  560.     /**
  561.      * @return ContainerInterface
  562.      */
  563.     public function getQueryTypeGeneratorFactories(): ContainerInterface
  564.     {
  565.         return $this->dataObjectQueryTypeGeneratorFactories;
  566.     }
  567.     /**
  568.      * @return ContainerInterface
  569.      */
  570.     public function getQueryOperatorFactories(): ContainerInterface
  571.     {
  572.         return $this->dataObjectQueryOperatorFactories;
  573.     }
  574.     /**
  575.      * @return LocaleServiceInterface
  576.      */
  577.     public function getLocaleService(): LocaleServiceInterface
  578.     {
  579.         return $this->localeService;
  580.     }
  581.     /**
  582.      * @return Factory
  583.      */
  584.     public function getModelFactory(): Factory
  585.     {
  586.         return $this->modelFactory;
  587.     }
  588.     /**
  589.      * @return Translator
  590.      */
  591.     public function getTranslator()
  592.     {
  593.         return $this->translator;
  594.     }
  595.     /**
  596.      * @param $dataTypes
  597.      */
  598.     public function registerDataObjectDataTypes($dataTypes)
  599.     {
  600.         $this->dataObjectDataTypes $dataTypes;
  601.     }
  602.     /**
  603.      * @param $dataTypes
  604.      */
  605.     public function registerAssetDataTypes($dataTypes)
  606.     {
  607.         $this->assetDataTypes $dataTypes;
  608.     }
  609.     /**
  610.      * @param $dataTypes
  611.      */
  612.     public function registerDocumentDataTypes($dataTypes)
  613.     {
  614.         $this->documentDataTypes $dataTypes;
  615.     }
  616.     /**
  617.      * @param $dataTypes
  618.      */
  619.     public function registerPropertyDataTypes($dataTypes)
  620.     {
  621.         $this->propertyDataTypes $dataTypes;
  622.     }
  623.     /**
  624.      * @param $dataTypes
  625.      */
  626.     public function registerClassificationStoreDataTypes($dataTypes)
  627.     {
  628.         $this->classificationStoreDataTypes $dataTypes;
  629.     }
  630.     /**
  631.      * @param $typename
  632.      *
  633.      * @return mixed
  634.      *
  635.      * @throws \Exception
  636.      */
  637.     public function getAssetTypeDefinition($typename)
  638.     {
  639.         if (isset($this->assetDataTypes[$typename])) {
  640.             return $this->assetDataTypes[$typename];
  641.         }
  642.         throw new ClientSafeException('unknown asset type: ' $typename);
  643.     }
  644.     /**
  645.      * @param $typename
  646.      *
  647.      * @return mixed
  648.      *
  649.      * @throws \Exception
  650.      */
  651.     public function getClassificationStoreTypeDefinition($typename)
  652.     {
  653.         if (isset($this->classificationStoreDataTypes[$typename])) {
  654.             return $this->classificationStoreDataTypes[$typename];
  655.         }
  656.         throw new ClientSafeException('unknown classificationstore type: ' $typename);
  657.     }
  658.     /**
  659.      * @param $typename
  660.      *
  661.      * @return mixed
  662.      *
  663.      * @throws \Exception
  664.      */
  665.     public function getDataObjectTypeDefinition($typename)
  666.     {
  667.         if (isset($this->dataObjectDataTypes[$typename])) {
  668.             return $this->dataObjectDataTypes[$typename];
  669.         }
  670.         throw new ClientSafeException('unknown dataobject type: ' $typename);
  671.     }
  672.     /**
  673.      * @param $typename
  674.      *
  675.      * @return mixed
  676.      *
  677.      * @throws \Exception
  678.      */
  679.     public function getDocumentTypeDefinition($typename)
  680.     {
  681.         if (isset($this->documentDataTypes[$typename])) {
  682.             return $this->documentDataTypes[$typename];
  683.         }
  684.         throw new ClientSafeException('unknown document type: ' $typename);
  685.     }
  686.     /**
  687.      * @param $typename
  688.      *
  689.      * @return mixed
  690.      *
  691.      * @throws \Exception
  692.      */
  693.     public function getPropertyTypeDefinition($typename)
  694.     {
  695.         if (isset($this->propertyDataTypes[$typename])) {
  696.             return $this->propertyDataTypes[$typename];
  697.         }
  698.         throw new ClientSafeException('unknown property type: ' $typename);
  699.     }
  700.     /**
  701.      * gets value for given object and getter, including inherited values
  702.      *
  703.      * @static
  704.      *
  705.      * @param $object
  706.      * @param $key
  707.      * @param null $brickType
  708.      * @param null $brickKey
  709.      * @param null $fieldDefinition
  710.      *
  711.      * @return \stdclass, value and objectid where the value comes from
  712.      */
  713.     public static function getValueForObject($object$key$brickType null$brickKey null$fieldDefinition null$context = [], $brickDescriptor null$args = [])
  714.     {
  715.         //TODO once this gets integrated into the core, share the code with Service::getValueFromObject
  716.         $getter 'get' ucfirst($key);
  717.         $value $object->$getter();
  718.         if (!empty($value) && !empty($brickType)) {
  719.             $getBrickType 'get' ucfirst($brickType);
  720.             $value $value->$getBrickType();
  721.             if (!empty($value) && !empty($brickKey)) {
  722.                 if ($brickDescriptor) {
  723.                     $innerContainer $brickDescriptor['innerContainer'] ? $brickDescriptor['innerContainer'] : 'localizedfields';
  724.                     $localizedFields $value->{'get' ucfirst($innerContainer)}();
  725.                     $brickDefinition Definition::getByKey($brickType);
  726.                     $fieldDefinitionLocalizedFields $brickDefinition->getFieldDefinition('localizedfields');
  727.                     $fieldDefinition $fieldDefinitionLocalizedFields->getFieldDefinition($brickKey);
  728.                     $value $localizedFields->getLocalizedValue($brickDescriptor['brickfield'], isset($args['language']) ? $args['language'] : null);
  729.                 } else {
  730.                     $brickFieldGetter 'get' ucfirst($brickKey);
  731.                     $value $value->$brickFieldGetter();
  732.                 }
  733.             }
  734.         }
  735.         if (!$fieldDefinition) {
  736.             $fieldDefinition $object->getClass()->getFieldDefinition($key$context);
  737.         }
  738.         if (!empty($brickType) && !empty($brickKey) && !$brickDescriptor) {
  739.             $brickClass Definition::getByKey($brickType);
  740.             $context = ['object' => $object'outerFieldname' => $key];
  741.             $fieldDefinition $brickClass->getFieldDefinition($brickKey$context);
  742.         }
  743.         if ($fieldDefinition->isEmpty($value)) {
  744.             $parent \Pimcore\Model\DataObject\Service::hasInheritableParentObject($object);
  745.             if (!empty($parent)) {
  746.                 return self::getValueForObject($parent$key$brickType$brickKey$fieldDefinition$context$brickDescriptor);
  747.             }
  748.         }
  749.         return $value;
  750.     }
  751.     /**
  752.      * @param $object
  753.      * @param Data $fieldDefinition
  754.      * @param string $attribute
  755.      * @param array $args
  756.      *
  757.      * @return \stdclass|null
  758.      *
  759.      * @throws \Exception
  760.      */
  761.     public static function setValue($object$attribute$callback)
  762.     {
  763.         $result null;
  764.         $setter $attribute 'set' ucfirst($attribute) : $attribute;
  765.         if (!$object) {
  766.             return null;
  767.         }
  768.         $container $object;
  769.         /** @var Concrete $element */
  770.         $attributeParts explode('~'$attribute);
  771.         $brickType null;
  772.         $brickKey null;
  773.         if (substr($attribute01) == '~') {
  774.             // key value, ignore for now
  775.         } elseif (count($attributeParts) > 1) {
  776.             // TODO once the datahub gets integrated into the core we should try to share this code
  777.             // with Pimcore\Model\DataObject\Service::gridObjectData
  778.             $context = ['object' => $object];
  779.             $brickDescriptor null;
  780.             // brick
  781.             $brickType $attributeParts[0];
  782.             if (strpos($brickType'?') !== false) {
  783.                 $brickDescriptor substr($brickType1);
  784.                 $brickDescriptor json_decode($brickDescriptortrue);
  785.                 $brickType $brickDescriptor['containerKey'];
  786.             }
  787.             $brickKey $attributeParts[1];
  788.             $key \Pimcore\Model\DataObject\Service::getFieldForBrickType($object->getclass(), $brickType);
  789.             $brickClass Definition::getByKey($brickType);
  790.             $context['outerFieldname'] = $key;
  791.             if ($brickDescriptor) {
  792.                 $def $brickClass->getFieldDefinition($brickKey);
  793.                 if (!$def) {
  794.                     $innerContainer $brickDescriptor['innerContainer'] ? $brickDescriptor['innerContainer'] : 'localizedfields';
  795.                     $localizedFields $brickClass->getFieldDefinition($innerContainer);
  796.                     $def $localizedFields->getFieldDefinition($brickDescriptor['brickfield']);
  797.                 }
  798.             } else {
  799.                 $def $brickClass->getFieldDefinition($brickKey$context);
  800.             }
  801.             if (!empty($key)) {
  802.                 // if the definition is not set try to get the definition from localized fields
  803.                 if (!$def) {
  804.                     if ($locFields $object->getClass()->getFieldDefinition('localizedfields')) {
  805.                         $def $locFields->getFieldDefinition($key$context);
  806.                     }
  807.                 }
  808.                 $brickGetter 'get' ucfirst($key);
  809.                 $brickContainer $object->$brickGetter();
  810.                 $subBrickGetter 'get' ucfirst($brickType);
  811.                 $subBrickSetter 'set' ucfirst($brickType);
  812.                 $subBrickType $brickContainer->$subBrickGetter();
  813.                 if (!$subBrickType) {
  814.                     /** @var $brickClass AbstractData */
  815.                     $brickClass 'Pimcore\\Model\\DataObject\\Objectbrick\\Data\\' ucfirst($brickType);
  816.                     $subBrickType = new $brickClass($object);
  817.                     $subBrickSetter 'set' ucfirst($brickType);
  818.                     $brickContainer->$subBrickSetter($subBrickType);
  819.                 }
  820.                 $innerSetter 'set' ucfirst($def->getName());
  821.                 $result $callback($subBrickType$innerSetter);
  822.                 $brickContainer->$subBrickSetter($subBrickType);
  823.                 return $result;
  824.             }
  825.         } elseif (method_exists($container$setter)) {
  826.             $result $callback($container$setter);
  827.         }
  828.         return $result;
  829.     }
  830.     /**
  831.      * @param BaseDescriptor $descriptor
  832.      * @param Data $fieldDefinition
  833.      * @param string $attribute
  834.      * @param array $args
  835.      *
  836.      * @return \stdclass|null
  837.      */
  838.     public static function resolveValue(BaseDescriptor $descriptorData $fieldDefinition$attribute$args = [])
  839.     {
  840.         $getter 'get' ucfirst($fieldDefinition->getName());
  841.         $objectId $descriptor['id'];
  842.         $object Concrete::getById($objectId);
  843.         if (!$object) {
  844.             return null;
  845.         }
  846.         $result null;
  847.         $container $object;
  848.         /** @var Concrete $element */
  849.         $attributeParts explode('~'$attribute);
  850.         $brickType null;
  851.         $brickKey null;
  852.         if ($descriptor instanceof FieldcollectionDescriptor) {
  853.             $descriptorData $descriptor->getArrayCopy();
  854.             $fcFieldNameGetter 'get' ucfirst($descriptorData['__fcFieldname']);
  855.             $fcData $object->$fcFieldNameGetter();
  856.             if ($fcData) {
  857.                 $items $fcData->getItems();
  858.                 $idx $descriptorData['__itemIdx'];
  859.                 $itemData $items[$idx];
  860.                 if (is_array($args) && isset($args['language'])) {
  861.                     $result $itemData->$getter($args['language']);
  862.                 } else {
  863.                     $result $itemData->$getter();
  864.                 }
  865.             }
  866.         }
  867.         if ($descriptor instanceof BlockDescriptor) {
  868.             $descriptorData $descriptor->getArrayCopy();
  869.             $blockData null;
  870.             if (isset($descriptorData['__fcFieldname']) && $descriptorData['__fcFieldname']) {
  871.                 $fcFieldNameGetter 'get' ucfirst($descriptorData['__fcFieldname']);
  872.                 $fcData $object->$fcFieldNameGetter();
  873.                 if ($fcData) {
  874.                     $items $fcData->getItems();
  875.                     $idx $descriptorData['__itemIdx'];
  876.                     $itemData $items[$idx];
  877.                     $result = [];
  878.                     $blockGetter 'get' ucfirst($descriptorData['__blockName']);
  879.                     $blockData call_user_func_array([$itemData$blockGetter], $descriptorData['args'] ?? []);
  880.                 }
  881.             } elseif (isset($descriptorData['__brickType']) && $descriptorData['__brickType']) {
  882.                 $context = ['object' => $object];
  883.                 $brickDescriptor null;
  884.                 $brickType $descriptorData['__brickType'];
  885.                 $brickKey $descriptorData['__brickKey'];
  886.                 $key \Pimcore\Model\DataObject\Service::getFieldForBrickType($object->getclass(), $brickType);
  887.                 $brickClass Definition::getByKey($brickType);
  888.                 if (!$brickClass) {
  889.                     return null;
  890.                 }
  891.                 $context['outerFieldname'] = $key;
  892.                 $def $brickClass->getFieldDefinition($brickKey$context);
  893.                 if (!$def) {
  894.                     return null;
  895.                 }
  896.                 if (!empty($key)) {
  897.                     $blockData self::getValueForObject($object$key$brickType$brickKey$def$context$brickDescriptor$args);
  898.                 }
  899.             } else {
  900.                 $blockGetter 'get'.ucfirst($descriptorData['__blockName']);
  901.                 $isLocalizedField self::isLocalizedField($container$fieldDefinition->getName());
  902.                 $blockData $object->$blockGetter($isLocalizedField && isset($descriptorData['args']['language']) ? $descriptorData['args']['language'] : null);
  903.             }
  904.             if ($blockData) {
  905.                 $index $descriptorData['__blockIndex'];
  906.                 $itemData $blockData[$index];
  907.                 $result $itemData[$descriptorData['__blockFieldName']]->getData();
  908.                 if (isset($descriptorData['__localized']) && $descriptorData['__localized']) {
  909.                     $result $result->getLocalizedValue($descriptorData['__localized'], $args['language'] ?? null);
  910.                 }
  911.             }
  912.         } elseif (substr($attribute01) == '~') {
  913.             // key value, ignore for now
  914.         } elseif (count($attributeParts) > 1) {
  915.             // TODO once the datahub gets integrated into the core we should try to share this code
  916.             // with Pimcore\Model\DataObject\Service::gridObjectData
  917.             $context = ['object' => $object];
  918.             $brickDescriptor null;
  919.             // brick
  920.             $brickType $attributeParts[0];
  921.             if (strpos($brickType'?') !== false) {
  922.                 $brickDescriptor substr($brickType1);
  923.                 $brickDescriptor json_decode($brickDescriptortrue);
  924.                 $brickType $brickDescriptor['containerKey'];
  925.             }
  926.             $brickKey $attributeParts[1];
  927.             $key \Pimcore\Model\DataObject\Service::getFieldForBrickType($object->getclass(), $brickType);
  928.             $brickClass Definition::getByKey($brickType);
  929.             $context['outerFieldname'] = $key;
  930.             if ($brickDescriptor) {
  931.                 $innerContainer $brickDescriptor['innerContainer'] ? $brickDescriptor['innerContainer'] : 'localizedfields';
  932.                 $localizedFields $brickClass->getFieldDefinition($innerContainer);
  933.                 $def $localizedFields->getFieldDefinition($brickDescriptor['brickfield']);
  934.             } else {
  935.                 $def $brickClass->getFieldDefinition($brickKey$context);
  936.             }
  937.             if (!empty($key)) {
  938.                 // if the definition is not set try to get the definition from localized fields
  939.                 if (!$def) {
  940.                     if ($locFields $object->getClass()->getFieldDefinition('localizedfields')) {
  941.                         $def $locFields->getFieldDefinition($key$context);
  942.                     }
  943.                 }
  944.                 $value self::getValueForObject($object$key$brickType$brickKey$def$context$brickDescriptor$args);
  945.                 return $value;
  946.             }
  947.         } elseif (method_exists($container$getter)) {
  948.             $isLocalizedField self::isLocalizedField($container$fieldDefinition->getName());
  949.             $result $container->$getter($isLocalizedField && isset($args['language']) ? $args['language'] : null);
  950.         }
  951.         return $result;
  952.     }
  953.     /**
  954.      * Check whether given field in container is localized
  955.      *
  956.      * @param Concrete|AbstractData|\Pimcore\Model\DataObject\Objectbrick\Data\AbstractData $container
  957.      * @param string $fieldName
  958.      *
  959.      * @return bool
  960.      */
  961.     private static function isLocalizedField($container$fieldName): bool
  962.     {
  963.         $containerDefinition null;
  964.         if ($container instanceof Concrete) {
  965.             $containerDefinition $container->getClass();
  966.         } elseif ($container instanceof AbstractData || $container instanceof \Pimcore\Model\DataObject\Objectbrick\Data\AbstractData) {
  967.             $containerDefinition $container->getDefinition();
  968.         }
  969.         if ($containerDefinition) {
  970.             if ($lfDefs $containerDefinition->getFieldDefinition('localizedfields')) {
  971.                 if ($lfDefs->getFieldDefinition($fieldName)) {
  972.                     return true;
  973.                 }
  974.             }
  975.         }
  976.         return false;
  977.     }
  978.     /**
  979.      * @return ContainerInterface
  980.      */
  981.     public function getDataObjectMutationTypeGeneratorFactories(): ContainerInterface
  982.     {
  983.         return $this->dataObjectMutationTypeGeneratorFactories;
  984.     }
  985.     /**
  986.      * @param ContainerInterface $mutationTypeGeneratorFactories
  987.      */
  988.     public function setDataObjectMutationTypeGeneratorFactories(ContainerInterface $dataObjectMutationTypeGeneratorFactories): void
  989.     {
  990.         $this->dataObjectMutationTypeGeneratorFactories $dataObjectMutationTypeGeneratorFactories;
  991.     }
  992.     /**
  993.      * @return ContainerInterface
  994.      */
  995.     public function getDataObjectMutationOperatorFactories(): ContainerInterface
  996.     {
  997.         return $this->dataObjectMutationOperatorFactories;
  998.     }
  999.     /**
  1000.      * @param ContainerInterface $dataObjectMutationOperatorFactories
  1001.      */
  1002.     public function setDataObjectMutationOperatorFactories(ContainerInterface $dataObjectMutationOperatorFactories): void
  1003.     {
  1004.         $this->dataObjectMutationOperatorFactories $dataObjectMutationOperatorFactories;
  1005.     }
  1006.     /**
  1007.      * @return array
  1008.      */
  1009.     public function getDataObjectDataTypes(): array
  1010.     {
  1011.         return $this->dataObjectDataTypes;
  1012.     }
  1013.     /**
  1014.      * @param array $data
  1015.      * @param AbstractElement $target
  1016.      * @param array $args
  1017.      * @param array $context
  1018.      * @param ResolveInfo|null $resolveInfo
  1019.      */
  1020.     public function extractData($data$target$args = [], $context = [], ResolveInfo $resolveInfo null)
  1021.     {
  1022.         $fieldHelper null;
  1023.         if ($target instanceof Document) {
  1024.             $fieldHelper $this->getDocumentFieldHelper();
  1025.         } elseif ($target instanceof Asset) {
  1026.             $fieldHelper $this->getAssetFieldHelper();
  1027.         } elseif ($target instanceof AbstractObject) {
  1028.             $fieldHelper $this->getObjectFieldHelper();
  1029.         }
  1030.         if ($fieldHelper) {
  1031.             $fieldHelper->extractData($data$target$args$context$resolveInfo);
  1032.         }
  1033.     }
  1034.     /**
  1035.      * @param string $type
  1036.      *
  1037.      * @return bool
  1038.      */
  1039.     public function querySchemaEnabled(string $type)
  1040.     {
  1041.         $context Runtime::get('datahub_context');
  1042.         /** @var $configuration Configuration */
  1043.         $configuration $context['configuration'];
  1044.         if ($type === 'object') {
  1045.             $types $configuration->getConfiguration()['schema']['queryEntities'];
  1046.             $enabled count($types) > 0;
  1047.         } else {
  1048.             $enabled $configuration->getSpecialEntities()[$type]['read'] ?? false;
  1049.         }
  1050.         return $enabled;
  1051.     }
  1052.     public function setTagManagerListener($tagManagerListener)
  1053.     {
  1054.         $this->tagManagerListener $tagManagerListener;
  1055.     }
  1056.     /**
  1057.      * @return mixed
  1058.      */
  1059.     public function getTagManagerListener()
  1060.     {
  1061.         return $this->tagManagerListener;
  1062.     }
  1063. }