Skip to content

Commit

Permalink
Fixed #2353
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jan 25, 2018
1 parent c2fff5b commit 1b968c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

### Fixed
- Fixed an error that could occur when calling `craft\helpers\UrlHelper` methods from the console. ([#2347](https://github.com/craftcms/cms/issues/2347))
- Fixed a bug where Matrix fields with equal Min Blocks and Max Blocks settings weren’t creating default blocks for existing elements. ([#2353](https://github.com/craftcms/cms/issues/2353))

## 3.0.0-RC7.1 - 2018-01-24

Expand Down
7 changes: 4 additions & 3 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ public function getInputHtml($value, ElementInterface $element = null): string
// Get the block types data
$blockTypeInfo = $this->_getBlockTypeInfoForInput($element);

$staticBlocks = ($this->minBlocks != 0 && $this->minBlocks == $this->maxBlocks && count($blockTypeInfo) === 1);
$createDefaultBlocks = $this->minBlocks != 0 && count($blockTypeInfo) === 1;
$staticBlocks = $createDefaultBlocks && $this->minBlocks == $this->maxBlocks;

Craft::$app->getView()->registerAssetBundle(MatrixAsset::class);

Expand All @@ -402,10 +403,10 @@ public function getInputHtml($value, ElementInterface $element = null): string
}

// Safe to set the default blocks?
if ($this->isFresh($element) && $this->minBlocks != 0 && count($blockTypeInfo) === 1 && $value === []) {
if ($createDefaultBlocks) {
$blockType = $this->getBlockTypes()[0];

for ($i = 0; $i < $this->minBlocks; $i++) {
for ($i = count($value); $i < $this->minBlocks; $i++) {
$block = new MatrixBlock();
$block->fieldId = $this->id;
$block->typeId = $blockType->id;
Expand Down

0 comments on commit 1b968c1

Please sign in to comment.