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

Đang mở Phù hợp với người mới
#682 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

Hướng nghiên cứu

Issue xác định copyCrossSiteValue() trong src/Field.php là điểm vào bị lỗi. Đọc cách xử lý giá trị nguồn null tại đó và kiểm tra cách getFieldValue() và setFieldValue() được sử dụng; tái hiện lỗi bằng cách sao chép từ một site có trường CKEditor để trống. Công việc hoàn tất khi giá trị trống được sao chép mà không xảy ra lỗi và thay thế giá trị đích.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
PHP
Star
47
Fork
35
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của craftcms/ckeditor

Tất cả issue của craftcms/ckeditor

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.