From 863b36e852c177a2bc5135b53d9fd0c0d3f46489 Mon Sep 17 00:00:00 2001 From: Marc Eichenseher Date: Fri, 19 Jul 2024 08:47:03 +0200 Subject: [PATCH 1/3] fix(quantityValue): Use null when no value was defined (#869) --- src/GraphQL/DataObjectInputProcessor/QuantityValue.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/DataObjectInputProcessor/QuantityValue.php b/src/GraphQL/DataObjectInputProcessor/QuantityValue.php index 2b9831c7..090bcae8 100644 --- a/src/GraphQL/DataObjectInputProcessor/QuantityValue.php +++ b/src/GraphQL/DataObjectInputProcessor/QuantityValue.php @@ -35,13 +35,17 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) $attribute = $this->getAttribute(); Service::setValue($object, $attribute, function ($container, $setter) use ($newValue) { if ($newValue) { + $value = null; $unit = null; + if (isset($newValue['value'])) { + $value = $newValue['value']; + } if (isset($newValue['unitId'])) { $unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getById($newValue['unitId']); } elseif (isset($newValue['unit'])) { $unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']); } - $quantityValue = new \Pimcore\Model\DataObject\Data\QuantityValue($newValue['value'], $unit); + $quantityValue = new \Pimcore\Model\DataObject\Data\QuantityValue($value, $unit); return $container->$setter($quantityValue); } From d0893cdf7ea487d49e545d650d68d5f2c0978514 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Wed, 31 Jul 2024 16:55:39 +0200 Subject: [PATCH 2/3] Fix Warning in Command MigrateLegacyConfig - Undefined array key "list" (#872) --- src/Command/Configuration/MigrateLegacyConfig.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Command/Configuration/MigrateLegacyConfig.php b/src/Command/Configuration/MigrateLegacyConfig.php index 4d4d18b8..f547b5b3 100644 --- a/src/Command/Configuration/MigrateLegacyConfig.php +++ b/src/Command/Configuration/MigrateLegacyConfig.php @@ -55,7 +55,7 @@ private function migrateToSettingsStore(string $id, string $scope, array $config private function migrateConfiguration(string $fileName, string $scope): void { $configs = $this->loadLegacyConfigs($fileName); - $configs = $configs['list']; + $configs = $configs['list'] ?? []; foreach ($configs as $key => $config) { $id = $config['general']['name']; $this->migrateToSettingsStore((string)$id, $scope, $config); @@ -63,8 +63,6 @@ private function migrateConfiguration(string $fileName, string $scope): void } /** - * - * * @return int|null * * @throws \Exception From d79d72d3198ad85bccf39b62114be8ba96651b19 Mon Sep 17 00:00:00 2001 From: mcop1 <89011527+mcop1@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:36:23 +0200 Subject: [PATCH 3/3] [Bug] Mutations to tables in Bricks (#875) * 863 tables inside bricks * Apply php-cs-fixer changes * 863 Refined approach * Apply php-cs-fixer changes --------- Co-authored-by: mcop1 --- src/Configuration.php | 2 - .../DataObjectInputProcessor/Table.php | 15 ++- .../Table.php | 2 +- src/GraphQL/Service.php | 92 ++++++++++++++----- 4 files changed, 84 insertions(+), 27 deletions(-) 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 []; + } }