From 630d7295fca25310f7f5ea897d67e36c9761d5c4 Mon Sep 17 00:00:00 2001 From: Peter van der Wal Date: Mon, 26 Jun 2023 14:06:36 +0200 Subject: [PATCH] fix: correctly update advanced relation metadata within brick (#761) Error: metadata from an AdvancedManyToManyRelation or AdvancedManyToManyObjectRelation field within a brick wasn't stored Caused by: ElementMetadata / ObjectMetadata was created with the "brickName~fieldName" notation, instead of the plain "fieldName" Resolved with: passing the real field name via the callback method --- .../AdvancedManyToManyObjectRelation.php | 4 ++-- .../DataObjectInputProcessor/AdvancedManyToManyRelation.php | 4 ++-- src/GraphQL/Service.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php index e4d969c8..accf7abc 100644 --- a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyObjectRelation.php @@ -38,7 +38,7 @@ class AdvancedManyToManyObjectRelation extends Base public function process($object, $newValue, $args, $context, ResolveInfo $info) { $attribute = $this->getAttribute(); - Service::setValue($object, $attribute, function ($container, $setter) use ($newValue, $attribute) { + Service::setValue($object, $attribute, function ($container, $setter, $fieldName) use ($newValue) { $result = []; if (is_array($newValue)) { foreach ($newValue as $newValueItemKey => $newValueItemValue) { @@ -53,7 +53,7 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) } } $concrete = Concrete::getById($element->getId()); - $item = new ObjectMetadata($attribute, $columns ?? [], $concrete); + $item = new ObjectMetadata($fieldName, $columns ?? [], $concrete); if (isset($data) === true) { $item->setData($data); } diff --git a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php index 4ec5da0c..fbc35d28 100644 --- a/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php +++ b/src/GraphQL/DataObjectInputProcessor/AdvancedManyToManyRelation.php @@ -38,7 +38,7 @@ class AdvancedManyToManyRelation extends Base public function process($object, $newValue, $args, $context, ResolveInfo $info) { $attribute = $this->getAttribute(); - Service::setValue($object, $attribute, function ($container, $setter) use ($newValue, $attribute) { + Service::setValue($object, $attribute, function ($container, $setter, $fieldName) use ($newValue) { $result = []; if (is_array($newValue)) { foreach ($newValue as $newValueItemKey => $newValueItemValue) { @@ -52,7 +52,7 @@ public function process($object, $newValue, $args, $context, ResolveInfo $info) $data[$metaDataValue['name']] = $metaDataValue['value']; } } - $item = new ElementMetadata($attribute, $columns ?? [], $element); + $item = new ElementMetadata($fieldName, $columns ?? [], $element); if (isset($data) === true) { $item->setData($data); } diff --git a/src/GraphQL/Service.php b/src/GraphQL/Service.php index 63ba02d8..c822efe0 100644 --- a/src/GraphQL/Service.php +++ b/src/GraphQL/Service.php @@ -919,14 +919,14 @@ public static function setValue($object, $attribute, $callback) } $innerSetter = 'set' . ucfirst($def->getName()); - $result = $callback($subBrickType, $innerSetter); + $result = $callback($subBrickType, $innerSetter, $def->getName()); $brickContainer->$subBrickSetter($subBrickType); return $result; } } elseif (method_exists($container, $setter)) { - $result = $callback($container, $setter); + $result = $callback($container, $setter, $attribute); } return $result;