From 7f6c47184c3ccdaa81001bfae41d6d700e6ff9ab Mon Sep 17 00:00:00 2001 From: i-just Date: Thu, 26 Feb 2026 12:20:26 +0100 Subject: [PATCH 1/6] only duplicate if the value was empty to begin with --- src/Field.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index e8abfc1a..189692e7 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1914,10 +1914,12 @@ public function setEnableSourceEditingForNonAdmins(bool $value): void */ public function propagateValue(ElementInterface $from, ElementInterface $to): void { + $wasValueEmpty = $this->isValueEmpty($to->getFieldValue($this->handle), $to); + /** @phpstan-ignore-next-line */ parent::propagateValue($from, $to); - if (!$from->propagateAll) { + if (!$from->propagateAll && $wasValueEmpty) { // NestedElementManager won't duplicate the nested entries automatically, // because the field has a value in the target site (the HTML content), so isValueEmpty() is false. /** @phpstan-ignore-next-line */ From f3151682223d89730e0a1167cc82d793dbe6e2ae Mon Sep 17 00:00:00 2001 From: i-just Date: Thu, 26 Feb 2026 12:20:45 +0100 Subject: [PATCH 2/6] don't trigger NEM duplication twice --- src/Field.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Field.php b/src/Field.php index 189692e7..5e63442e 100644 --- a/src/Field.php +++ b/src/Field.php @@ -11,6 +11,7 @@ use craft\base\CrossSiteCopyableFieldInterface; use craft\base\ElementContainerFieldInterface; use craft\base\ElementInterface; +use craft\base\Event; use craft\base\FieldInterface; use craft\base\MergeableFieldInterface; use craft\base\NestedElementInterface; @@ -38,6 +39,7 @@ use craft\enums\PropagationMethod; use craft\errors\InvalidHtmlTagException; use craft\events\CancelableEvent; +use craft\events\DraftEvent; use craft\events\DuplicateNestedElementsEvent; use craft\helpers\ArrayHelper; use craft\helpers\Cp; @@ -56,6 +58,7 @@ use craft\models\ImageTransform; use craft\models\Section; use craft\models\Volume; +use craft\services\Drafts; use craft\services\ElementSources; use craft\web\View; use GraphQL\Type\Definition\Type; @@ -1925,5 +1928,20 @@ public function propagateValue(ElementInterface $from, ElementInterface $to): vo /** @phpstan-ignore-next-line */ self::entryManager($this)->duplicateNestedElements($from, $to, force: true); } + + // when the field is translatable (e.g. for each site); + // you create a new entry and add nested entry into a cke field while the entry is fresh + // during autosave, that nested entry gets duplicated into the other site correctly (along with value adjustment) + // however when you then fully save the owner, + // the duplication is triggered twice - during Drafts::applyDraft() and during Drafts::removeDraftData() + // the changes in 5.9.0 mean that the nested entries get duplicated and adjusted twice + // (via NEM::saveNestedElements > duplicateNestedElements() route) + // causing the nested entry in the site we propagated to, to have a wrong ID + // the CKE content references X, but X nested entry is marked as deleted and Y nested entry was created in its place + Event::on(Drafts::class, Drafts::EVENT_BEFORE_APPLY_DRAFT, function (DraftEvent $event) { + if ($event->draft->propagateAll && $event->canonical->id === $event->draft->id) { + $event->draft->propagateAll = false; + } + }); } } From 7a9c138c6bbbb7ea1dad269072496880fbb027f6 Mon Sep 17 00:00:00 2001 From: i-just Date: Thu, 26 Feb 2026 12:42:18 +0100 Subject: [PATCH 3/6] tweak the comment --- src/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index 5e63442e..ad47cdc1 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1933,7 +1933,7 @@ public function propagateValue(ElementInterface $from, ElementInterface $to): vo // you create a new entry and add nested entry into a cke field while the entry is fresh // during autosave, that nested entry gets duplicated into the other site correctly (along with value adjustment) // however when you then fully save the owner, - // the duplication is triggered twice - during Drafts::applyDraft() and during Drafts::removeDraftData() + // the duplication is triggered twice - from ElementsController::actionApplyDraft() and from Drafts::removeDraftData() // the changes in 5.9.0 mean that the nested entries get duplicated and adjusted twice // (via NEM::saveNestedElements > duplicateNestedElements() route) // causing the nested entry in the site we propagated to, to have a wrong ID From b4fad180c026866dc8912dd1d87d704bfdd55cf1 Mon Sep 17 00:00:00 2001 From: i-just Date: Thu, 26 Feb 2026 12:47:38 +0100 Subject: [PATCH 4/6] change the condition --- src/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index ad47cdc1..d93af619 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1939,7 +1939,7 @@ public function propagateValue(ElementInterface $from, ElementInterface $to): vo // causing the nested entry in the site we propagated to, to have a wrong ID // the CKE content references X, but X nested entry is marked as deleted and Y nested entry was created in its place Event::on(Drafts::class, Drafts::EVENT_BEFORE_APPLY_DRAFT, function (DraftEvent $event) { - if ($event->draft->propagateAll && $event->canonical->id === $event->draft->id) { + if ($event->draft->propagateAll && $event->draft->getIsUnpublishedDraft()) { $event->draft->propagateAll = false; } }); From 0f20ca4ac03675e6e8a7cd4def22597ee0e1c09a Mon Sep 17 00:00:00 2001 From: i-just Date: Thu, 26 Feb 2026 12:52:00 +0100 Subject: [PATCH 5/6] ecs --- src/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index d93af619..f000a743 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1938,7 +1938,7 @@ public function propagateValue(ElementInterface $from, ElementInterface $to): vo // (via NEM::saveNestedElements > duplicateNestedElements() route) // causing the nested entry in the site we propagated to, to have a wrong ID // the CKE content references X, but X nested entry is marked as deleted and Y nested entry was created in its place - Event::on(Drafts::class, Drafts::EVENT_BEFORE_APPLY_DRAFT, function (DraftEvent $event) { + Event::on(Drafts::class, Drafts::EVENT_BEFORE_APPLY_DRAFT, function(DraftEvent $event) { if ($event->draft->propagateAll && $event->draft->getIsUnpublishedDraft()) { $event->draft->propagateAll = false; } From 58b687542a69d3eb72040cccfa26b8f03f781ca4 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 2 Mar 2026 14:26:10 -0800 Subject: [PATCH 6/6] Release note [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 821a5cab..657a2d6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Fixed an error that could occur when creating a nested entry. ([#505](https://github.com/craftcms/ckeditor/issues/505)) - Fixed a bug where `&nbps;` briefly appeared below the editor on page load, if the “Show word count” setting was enabled. ([#507](https://github.com/craftcms/ckeditor/issues/507)) ## 4.11.1 - 2026-02-18