Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1914,14 +1917,31 @@ 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 */
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 - 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
// 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->draft->getIsUnpublishedDraft()) {
$event->draft->propagateAll = false;
}
});
}
}