diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f25ef3df..ab57d9166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Fixed broken Twig try tag when catch has not been defined or is empty * Fixed `FlexForm` serialization * Fixed form validation for numeric values in PHP 8 + * Fixed `flex-options@` in blueprints duplicating items in array # v1.7.18 ## 07/19/2021 diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index adbfce6d2..402c9746d 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -831,7 +831,7 @@ class FlexDirectory implements FlexDirectoryInterface * @param array $call * @return void */ - protected function dynamicFlexField(array &$field, $property, array $call) + protected function dynamicFlexField(array &$field, $property, array $call): void { $params = (array)$call['params']; $object = $call['object'] ?? null; @@ -840,11 +840,28 @@ class FlexDirectory implements FlexDirectoryInterface if ($object && method_exists($object, $method)) { $value = $object->{$method}(...$params); if (is_array($value) && isset($field[$property]) && is_array($field[$property])) { - $field[$property] = array_merge_recursive($field[$property], $value); + $value = $this->mergeArrays($field[$property], $value); + } + $field[$property] = $value; + } + } + + /** + * @param array $array1 + * @param array $array2 + * @return array + */ + protected function mergeArrays(array $array1, array $array2): array + { + foreach ($array2 as $key => $value) { + if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) { + $array1[$key] = $this->mergeArrays($array1[$key], $value); } else { - $field[$property] = $value; + $array1[$key] = $value; } } + + return $array1; } /**