diff --git a/src/Configuration.php b/src/Configuration.php index d13afa4b..b38d2855 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -424,8 +424,6 @@ public function __clone(): void /** * @internal * - * @param ?User $user - * * @return bool */ public function isAllowed(string $type, ?User $user = null) diff --git a/src/GraphQL/DataObjectInputProcessor/Table.php b/src/GraphQL/DataObjectInputProcessor/Table.php index 78bf8ea0..6a4aba2c 100644 --- a/src/GraphQL/DataObjectInputProcessor/Table.php +++ b/src/GraphQL/DataObjectInputProcessor/Table.php @@ -44,8 +44,19 @@ public function __construct(array $nodeDef, array $processors) public function process($object, $newValue, $args, $context, ResolveInfo $info) { $attribute = $this->getAttribute(); - $getter = 'get' . ucfirst($attribute); - $currentTable = $object->$getter(); + $objectBrickParts = Service::parseObjectBrickFieldName($attribute); + + if(empty($objectBrickParts)) { + $getter = 'get' . ucfirst($attribute); + $currentTable = $object->$getter(); + } else { + $currentTable = Service::getValueFromObjectBrick( + $object, + $objectBrickParts['brickType'], + $objectBrickParts['brickKey'], + $objectBrickParts['brickDescriptor'] ?? null + ); + } Service::setValue($object, $attribute, function ($container, $setter) use ($newValue, $currentTable) { $newTable = []; diff --git a/src/GraphQL/DataObjectMutationFieldConfigGenerator/Table.php b/src/GraphQL/DataObjectMutationFieldConfigGenerator/Table.php index bf7f7725..1b42eff1 100644 --- a/src/GraphQL/DataObjectMutationFieldConfigGenerator/Table.php +++ b/src/GraphQL/DataObjectMutationFieldConfigGenerator/Table.php @@ -25,7 +25,7 @@ class Table extends Base public function getGraphQlMutationFieldConfig($nodeDef, $class, $container = null, $params = []) { $fieldName = $nodeDef['attributes']['attribute']; - $tableDef = $class->getFieldDefinition($fieldName); + $tableDef = $this->getGraphQlService()->getObjectFieldHelper()->getFieldDefinitionFromKey($class, $fieldName); $inputItems = []; $numCols = 0; diff --git a/src/GraphQL/Service.php b/src/GraphQL/Service.php index c4ecd800..0458acde 100644 --- a/src/GraphQL/Service.php +++ b/src/GraphQL/Service.php @@ -53,6 +53,7 @@ use Pimcore\Model\Factory; use Pimcore\Translation\Translator; use Psr\Container\ContainerInterface; +use stdClass; class Service { @@ -782,7 +783,7 @@ public function getPropertyTypeDefinition($typeName) * @param string|null $brickKey * @param Data|null $fieldDefinition * - * @return \stdclass, value and objectid where the value comes from + * @return stdclass, value and objectid where the value comes from */ public static function getValueForObject($object, $key, $brickType = null, $brickKey = null, $fieldDefinition = null, $context = [], $brickDescriptor = null, $args = []) { @@ -837,7 +838,7 @@ public static function getValueForObject($object, $key, $brickType = null, $bric * @param string $attribute * @param \Closure $callback * - * @return \stdclass|null + * @return stdclass|null * * @throws \Exception */ @@ -976,31 +977,18 @@ public static function resolveValue(BaseDescriptor $descriptor, Data $fieldDefin $blockData = call_user_func_array([$itemData, $blockGetter], $descriptorData['args'] ?? []); } } elseif (isset($descriptorData['__brickType']) && $descriptorData['__brickType']) { - $context = ['object' => $object]; $brickDescriptor = $descriptorData['__brickDescriptor'] ?? null; $brickType = $descriptorData['__brickType']; $brickKey = $descriptorData['__brickKey']; - $key = \Pimcore\Model\DataObject\Service::getFieldForBrickType($object->getclass(), $brickType); - - $brickClass = Definition::getByKey($brickType); - - if (!$brickClass) { - return null; - } - - $context['outerFieldname'] = $key; - - $def = $brickClass->getFieldDefinition($brickKey, $context); - - if (!$def) { - return null; - } - - if (!empty($key)) { - $blockData = self::getValueForObject($object, $key, $brickType, $brickKey, $def, $context, $brickDescriptor, $descriptorData['args'] ?? []); - } + return self::getValueFromObjectBrick( + $object, + $brickType, + $brickKey, + $brickDescriptor, + $descriptorData + ); } else { $blockGetter = 'get'.ucfirst($descriptorData['__blockName']); $isLocalizedField = self::isLocalizedField($container, $fieldDefinition->getName()); @@ -1169,4 +1157,64 @@ public function querySchemaEnabled(string $type) return $enabled; } + + public static function getValueFromObjectBrick( + Concrete $object, + string $brickType, + string $brickKey, + string $brickDescriptor = null, + array $descriptorData = [], + ): stdClass|array|null { + $context = ['object' => $object]; + + $key = \Pimcore\Model\DataObject\Service::getFieldForBrickType($object->getclass(), $brickType); + $brickClass = Definition::getByKey($brickType); + if (!$brickClass) { + return null; + } + + $context['outerFieldname'] = $key; + $def = $brickClass->getFieldDefinition($brickKey, $context); + if (!$def) { + return null; + } + + if (!empty($key)) { + return self::getValueForObject( + $object, + $key, + $brickType, + $brickKey, + $def, + $context, + $brickDescriptor, + $descriptorData['args'] ?? []); + } + + return null; + } + + public static function parseObjectBrickFieldName( + string $fieldName + ): array { + $parts = explode('~', $fieldName); + if (count($parts) > 1) { + [$brickType, $brickKey] = $parts; + $brickDescriptor = null; + + if (strpos($brickType, '?') !== false) { + $brickDescriptor = substr($brickType, 1); + $brickDescriptor = json_decode($brickDescriptor, true); + $brickType = $brickDescriptor['containerKey']; + } + + return [ + 'brickType' => $brickType, + 'brickKey' => $brickKey, + 'brickDescriptor' => $brickDescriptor, + ]; + } + + return []; + } }