#default_value breaks tests for ckeditor5 fields

Created on 16 April 2023, over 1 year ago
Updated 3 May 2023, over 1 year ago

Problem/Motivation

FunctionalJavascript tests fail when a text_format ckeditor5 field is given a #default_value property.

Steps to reproduce

  1. create a custom entity with a text_long field
  2. create a form for creating/editing this entity
  3. when a new entity is being created, omit the #default_value property
  4. when an existing entity is being edited, load the entity and assign the field's value to the #default_value property
  5. create a FunctionalJavascript test and have it create a new instance of the custom entity
  6. test to verify that the value assigned to the field is stored in the entity; the test will pass
  7. assign a new value to the field and re-save the entity
  8. test to verify that the entity has the new value
  9. note that the test fails, because the entity has the value assigned to the #default_value property

I am attaching a repro case to demonstrate the failing test. I can see in the debugger that $form_state->getValue() gets the original value when the #default_value property is used. I can also see, when I add calls to $this->createScreenshot() that the new value is being correctly set on the form.

Proposed resolution

Use the new value given to the ckeditorInstance instead of the value assigned to the #default_value property of the form's field in its render array.

🐛 Bug report
Status

Active

Version

9.5

Component
CKEditor 5 

Last updated 2 days ago

Created by

🇺🇸United States bkline Virginia

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @bkline
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Thanks for the detailed bug report! 👏🙏

    The next thing we need is a failing automated test. That will make it far easier for anybody else to start working on the fix. It sounds like you would be more than able to do that? 😄

  • Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Not currently mergeable.
  • @bklinerksystemscom opened merge request.
Production build 0.71.5 2024