Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.7' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mcop1 committed Aug 22, 2024
2 parents 8884817 + d79d72d commit e5bb884
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/Command/Configuration/MigrateLegacyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,14 @@ 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);
}
}

/**
*
*
* @return int|null
*
* @throws \Exception
Expand Down
2 changes: 0 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,6 @@ public function __clone(): void
/**
* @internal
*
* @param ?User $user
*
* @return bool
*/
public function isAllowed(string $type, ?User $user = null)
Expand Down
6 changes: 5 additions & 1 deletion src/GraphQL/DataObjectInputProcessor/QuantityValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 13 additions & 2 deletions src/GraphQL/DataObjectInputProcessor/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
92 changes: 70 additions & 22 deletions src/GraphQL/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use Pimcore\Model\Factory;
use Pimcore\Translation\Translator;
use Psr\Container\ContainerInterface;
use stdClass;

class Service
{
Expand Down Expand Up @@ -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 = [])
{
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 [];
}
}

0 comments on commit e5bb884

Please sign in to comment.