Skip to content

Commit

Permalink
Fixed revision bug
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Mar 14, 2024
1 parent 29fcb59 commit bb50647
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added the “‘New’ Button Label” field setting. ([#159](https://github.com/craftcms/ckeditor/discussions/159))
- Copy/pasting nested entry cards now duplicates the nested entries. ([#186](https://github.com/craftcms/ckeditor/issues/186), [#192](https://github.com/craftcms/ckeditor/pull/192))
- Fixed a bug where it was possible to copy/paste nested entry cards between CKEditor fields. ([#192](https://github.com/craftcms/ckeditor/pull/192))
- Fixed a bug where additional revisions were getting created when saving entries with CKEditor-nested entries.

## 4.0.0-beta.10 - 2024-03-12

Expand Down
4 changes: 4 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ function(array $match) use ($oldEntryIds, $newEntryIds) {
}

if ($resave) {
// set resaving=true to avoid our EVENT_AFTER_PROPAGATE handler from dealing with the owner recursively,
// and to avoid a new revision getting created.
$owner->resaving = true;

Craft::$app->getElements()->saveElement($owner, false, $propagate, false);
}
}
Expand Down
17 changes: 5 additions & 12 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,14 @@ public function init()
}
});

// keep track of which elements we're already in the middle of working on,
// so we don't end up redundantly maintaining nested elements
$activeElements = [];

Event::on(Element::class, Element::EVENT_AFTER_PROPAGATE, function(ModelEvent $event) use (&$activeElements) {
Event::on(Element::class, Element::EVENT_AFTER_PROPAGATE, function(ModelEvent $event) {
/** @var Element $element */
$element = $event->sender;
if (isset($activeElements[$element->id])) {
return;
}
$activeElements[$element->id] = true;
foreach ($this->entryManagers($element) as $entryManager) {
$entryManager->maintainNestedElements($element, $event->isNew);
if (!$element->resaving) {
foreach ($this->entryManagers($element) as $entryManager) {
$entryManager->maintainNestedElements($element, $event->isNew);
}
}
unset($activeElements[$element->id]);
});

Event::on(Element::class, Element::EVENT_BEFORE_DELETE, function(ModelEvent $event) {
Expand Down

0 comments on commit bb50647

Please sign in to comment.