Skip to content

Commit

Permalink
Fixed #2498
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 26, 2018
1 parent 21d13d4 commit 80894d3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Changed
- Craft now throws an exception if it detects that a `max_input_vars` error occurred. ([#876](https://github.com/craftcms/cms/issues/876))

### Fixed
- Fixed a bug where entry version data was not including newly-created Matrix block IDs, so they would be re-created from scratch when loading the version. ([#2498](https://github.com/craftcms/cms/issues/2498))

## 2.6.3010 - 2018-02-21

### Changed
Expand Down
1 change: 1 addition & 0 deletions src/fieldtypes/MatrixFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ public function prepValueFromPost($data)
if (strncmp($blockId, 'new', 3) === 0 || !isset($oldBlocksById[$blockId]))
{
$block = new MatrixBlockModel();
$block->postId = $blockId;
$block->fieldId = $this->model->id;
$block->typeId = $blockType->id;
$block->ownerId = $ownerId;
Expand Down
1 change: 1 addition & 0 deletions src/models/MatrixBlockModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ protected function defineAttributes()
'typeId' => AttributeType::Number,
'sortOrder' => AttributeType::Number,

'postId' => AttributeType::String,
'collapsed' => AttributeType::Bool,
));
}
Expand Down
17 changes: 17 additions & 0 deletions src/services/MatrixService.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@ public function saveField(MatrixFieldType $fieldType)
$blocks = array();
}

$allPostContent = $owner->getContentFromPost();
$postContent = isset($allPostContent[$field->handle]) ? $allPostContent[$field->handle] : null;
$newPostContent = array();

$transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null;
try
{
Expand All @@ -888,6 +892,13 @@ public function saveField(MatrixFieldType $fieldType)
{
$collapsedBlockIds[] = $block->id;
}

// Update the post content
$postId = $block->postId ?: $block->id;
if (isset($postContent[$postId]))
{
$newPostContent[$block->id] = $postContent[$postId];
}
}

// Get the IDs of blocks that are row deleted
Expand Down Expand Up @@ -931,6 +942,12 @@ public function saveField(MatrixFieldType $fieldType)
throw $e;
}

// Update the post content on the owner element
if ($postContent !== null)
{
$owner->setRawPostContent($field->handle, $newPostContent);
}

// Tell the browser to collapse any new block IDs
if (!craft()->isConsole() && $collapsedBlockIds)
{
Expand Down

0 comments on commit 80894d3

Please sign in to comment.