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

オープン 初心者向け
#682 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

issue では、src/Field.php の copyCrossSiteValue() が失敗するエントリポイントとして示されています。そこで null のソース値の処理を読み、getFieldValue() と setFieldValue() がどのように使われているかを確認します。CKEditor フィールドが空のサイトからコピーして再現します。空の値がエラーなくコピーされ、コピー先の値を置き換えれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
PHP
スター
47
フォーク
35
平均マージ
1日 2時間
マージ済み PR(30日)
25

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

craftcms/ckeditor のほかの issue

craftcms/ckeditor の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。