Skip to content

Commit

Permalink
craftcms#1184 Different Matrix Block Types are merged together
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanBereznev committed Aug 31, 2022
1 parent 137e8fa commit 6278531
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}


Expand Down

0 comments on commit 6278531

Please sign in to comment.