"Copy values from site" throws when the source CKEditor field is empty

Open Beginner friendly
#682 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

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

repo:ckeditor
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>&nbsp;</p>), so the request errors and nothing is copied.

Steps to reproduce
  1. Set up two sites, and add a CKEditor field that's translated per site to an entry type enabled for both.
  2. Save an entry with the field empty on site A and filled in on site B.
  3. 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from craftcms/ckeditor

All issues in craftcms/ckeditor

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.