diff --git a/src/fields/Matrix.php b/src/fields/Matrix.php index 06eaf7dd..0e38fd7c 100644 --- a/src/fields/Matrix.php +++ b/src/fields/Matrix.php @@ -139,8 +139,9 @@ public function parseField(): mixed // sub-field data that could be arrays or single values. Let's build our Matrix-ready data foreach ($fieldData as $blockSubFieldHandle => $value) { $handles = explode('.', $blockSubFieldHandle); - $blockIndex = 'new' . ($handles[0] + 1); $blockHandle = $handles[1]; + // Inclusion of block handle here prevents blocks of different types from being merged together + $blockIndex = 'new' . $blockHandle . ($handles[0] + 1); $subFieldHandle = $handles[2]; $disabled = Hash::get($this->fieldInfo, 'blocks.' . $blockHandle . '.disabled', false); @@ -155,7 +156,16 @@ public function parseField(): mixed // $order++; } - return Hash::expand($preppedData); + $expanded = Hash::expand($preppedData); + + // Although it seems to work with block handles in keys, it's better to keep things clean + $index = 1; + $resultBlocks = []; + foreach ($expanded as $blockData) { + $resultBlocks['new' . $index++] = $blockData; + } + + return $resultBlocks; }