"Copy values from site" throws when the source CKEditor field is empty
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 78/100
Research direction
The issue identifies copyCrossSiteValue() in src/Field.php as the failing entry point. Read the null source value handling there and check how getFieldValue() and setFieldValue() are used; reproduce by copying from a site where the CKEditor field is empty. Done means the empty value copies without an error and replaces the destination value.
Written by the indexing model from the issue text.
Description
Description
Copying a CKEditor field's value from another site fails with an error when that field is empty on the source site:
Error: Call to a member function getChunks() on null
#0 craft\ckeditor\Field::copyCrossSiteValue() (src/Field.php:1399)
#1 craft\controllers\ElementsController::actionCopyValuesFromSite() (src/controllers/ElementsController.php:653)
copyCrossSiteValue() reads the source value with $from->getFieldValue($this->handle) (typed FieldData|null in the docblock) and calls $fromValue->getChunks(false) on it without a null check. HtmlField::normalizeValue() returns null for an empty field ('', <p></p>, <p><br></p> or <p> </p>), so the request errors and nothing is copied.
Steps to reproduce
- Set up two sites, and add a CKEditor field that's translated per site to an entry type enabled for both.
- Save an entry with the field empty on site A and filled in on site B.
- Open the entry on site B and use "Copy values from site" to copy that field from site A.
Expected behavior
The empty value is copied to site B.
Actual behavior
The request fails with Call to a member function getChunks() on null, and the field on site B keeps its old value.
Possible fix
Return early when the source value is null:
$fromValue = $from->getFieldValue($this->handle);
if ($fromValue === null) {
$to->setFieldValue($this->handle, null);
return;
}
Craft CMS version
5.12.1
Plugin version
5.9.0 (the same code is in 5.10.0 and on the 5.x branch)
PHP version
8.4
Operating system and version
Linux (Docker)
Database type and version
MySQL 8
Image driver and version
No response
Installed plugins and modules
No response
- Dominant language
- PHP
- Stars
- 47
- Forks
- 35
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from craftcms/ckeditor
-
[6.x] Inline styles (alignment, font color, background color) are stripped on savePossibly taken @i-just claimed this today. Openrepo:ckeditor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
craftcms/ckeditor#676 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 52/100
craftcms/ckeditor#678 · 1 comment ·
Maintainers usually reply within 1 day
-
bug repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 40/100
craftcms/ckeditor#665 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
[6.x]: Esc in a fullscreen CKEditor field closes Preview instead of leaving fullscreenPossibly taken @i-just claimed this 15 days ago. Openbug repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 58/100
craftcms/ckeditor#651 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
bug repo:ckeditor
Difficulty 3/5 1-2 days Newbie friendliness 54/100
craftcms/ckeditor#646 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
All issues in craftcms/ckeditor
Similar issues
-
component/core domain/framework
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area: explore bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
nplhse/collaborative-ivena-statistics#2107 ·
Maintainers usually reply within 1 day