Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure matrix blocks added on Matrix->inputHtml() are registered as delta changes #12983

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fixed a bug where selectize inputs didn’t have a minimum width. ([#12950](https://github.com/craftcms/cms/issues/12950))
- Fixed a bug where the wrong tab would appear to be initially selected after an autosave, if the selected tab had changed during the autosave. ([#12960](https://github.com/craftcms/cms/issues/12960))
- Fixed a bug where it wasn’t possible to add a Dropdown field without a blank option to a global set. ([#12965](https://github.com/craftcms/cms/issues/12965))
- Fixed a bug where automatically-added Matrix blocks (per the field’s Min Blocks setting) were getting discarded if no changes were made to them. ([#12973](https://github.com/craftcms/cms/issues/12973))

## 4.4.5 - 2023-03-21

Expand Down
9 changes: 8 additions & 1 deletion src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,14 @@ protected function inputHtml(mixed $value, ?ElementInterface $element = null): s
');';

// Safe to create the default blocks?
if ($createDefaultBlocks) {
if ($createDefaultBlocks && count($value) < $this->minBlocks) {
// @link https://github.com/craftcms/cms/issues/12973
// for matrix fields with minBlocks set Craft.MatrixInput.addBlock() is called before new Craft.ElementEditor(),
// so when we get our initialSerializedValue() for the ElementEditor,
// the matrix block is already there which means the field is reported as not changed since the init
// and so not passed to PHP for save
$view->setInitialDeltaValue($this->handle, null);

$blockTypeJs = Json::encode($blockTypes[0]->handle);
for ($i = count($value); $i < $this->minBlocks; $i++) {
$js .= "\nmatrixInput.addBlock($blockTypeJs, null, false);";
Expand Down