Skip to content

Commit

Permalink
fix: correctly update advanced relation metadata within brick (#761)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
youwe-petervanderwal authored and dvesh3 committed Jul 31, 2023
1 parent b90a374 commit 630d729
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 630d729

Please sign in to comment.