Skip to content

Commit

Permalink
Hopefully fix #929
Browse files Browse the repository at this point in the history
  • Loading branch information
ttempleton committed Oct 24, 2024
1 parent 7f2008c commit e57caec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

### Fixed
- Fixed a bug where previously existing blocks could be lost when new blocks had validation errors, if `autosaveDrafts` was disabled

## 5.2.12 - 2024-10-21

### Added
Expand Down
18 changes: 6 additions & 12 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use craft\db\Table;
use craft\elements\db\ElementQueryInterface;
use craft\elements\User;
use craft\enums\AttributeStatus;
use craft\enums\Color;
use craft\enums\PropagationMethod;
use craft\errors\InvalidFieldException;
Expand Down Expand Up @@ -644,6 +643,12 @@ protected function inputHtml(mixed $value, ?ElementInterface $element = null, bo
$view->setInitialDeltaValue($this->handle, null);
}

// If not autosaving drafts and validation errors occurred, ensure previously existing blocks don't get lost
// TODO: autosaveDrafts is deprecated, remove this when it is removed from Craft
if (!Craft::$app->getConfig()->getGeneral()->autosaveDrafts && $element?->hasErrors()) {
$view->setInitialDeltaValue($this->handle, null);
}

return $view->renderTemplate('neo/input', [
'handle' => $this->handle,
'blocks' => $blocks,
Expand Down Expand Up @@ -802,17 +807,6 @@ public function getIsTranslatable(?ElementInterface $element = null): bool
return $this->propagationMethod !== PropagationMethod::All;
}

/**
* @inheritdoc
*/
public function getStatus(ElementInterface $element): ?array
{
return $element->isFieldOutdated($this->handle) ? [
AttributeStatus::Outdated,
Craft::t('app', 'This field was updated in the Current revision.'),
] : null;
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit e57caec

Please sign in to comment.