Problem/Motivation

The Editor module tracks when an editor has modified a field, and reverts the value of a field when its editor has not made any changes. When editing HTML source in CKEditor, the "change" event is not fired and the field is not flagged as having been changed, which will cause the field to be reverted in some conditions.

Steps to reproduce

  1. Edit a node with a body field that uses CKEditor.
  2. Press "Source" in the CKEditor instance, without making any other changes.
  3. Change the source to anything you like.
  4. Use the code inspector to inspect the accompanying, hidden textarea (its name will be "body[0][value]").
  5. The "data-editor-value-is-changed" attribute should be "true", but is not.
  6. Click "Source" again.
  7. Inspect the textarea again. The "data-editor-value-is-changed" is now correctly set to "true".

Proposed resolution

Using a solution similar to what is outlined at https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_editor.html#even..., add code to behave similarly to the change event handler.

Remaining tasks

Develop and test.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

n/a

Issue fork drupal-3275611

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

justin2pin created an issue. See original summary.

justin2pin’s picture

Issue tags: +Needs tests
justin2pin’s picture

Status: Active » Needs review
Issue tags: -Needs tests

Added test coverage

joelsteidl’s picture

I recently hit this issue and can confirm this patch handles it.

To test, I edited a piece of content and added a link manually in the source. The attribute mentioned data-editor-value-is-changed is set to true now.

yogeshmpawar made their first commit to this issue’s fork.

anybody’s picture

Experienced the issue at #3275082: Changes in CKEditor "Source" not saved - thanks for finding the reason and fixing it @justin2pin! :)
RTBC+1

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andrea.cividini’s picture

StatusFileSize
new2 KB

Thanks for providing a solution. Attaching a patch ready to use, for someone that needs a quick solution for it's production project like I do. Warning: I stripped the tests from the patch, only actual bugfixing code changes are in there.
RTBC +1

anybody’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Marking the MR RTBC. @andrea.cividini can you confirm the MR works as expected and fixes the issue?

Setting the priority to major as content editors may lose their input unexpectedly.

anybody’s picture

Version: 9.5.x-dev » 9.4.x-dev

Setting target version to 9.4.x as this is a major bugfix and no disruptive change.

andrea.cividini’s picture

@Anybody yes it is working as expected

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Nice test!

A few questions:

  1. Is this an upstream bug - should it be fixed there instead?
  2. What about ckeditor 5 - does it have the same problem.

Also we need a Drupal 10 version of the MR too as the current 9.x MR does not apply there.

ravi.shankar’s picture

StatusFileSize
new2 KB
new1.05 KB

Added reroll of patch #9 on Drupal 10.1.x., still needs work for point 1 and 2 of comment #13.

quietone’s picture

Project: Drupal core » CKEditor 4 - WYSIWYG HTML editor
Version: 9.4.x-dev » 1.0.x-dev
Component: ckeditor.module » Code

CKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0

ashwinsh’s picture

I am facing same issue with CKEditor Source mode with Site studio.

adinancenci’s picture

StatusFileSize
new1.5 KB

Re-roll of patch #14 for 1.0.2

jacqui1811’s picture

@ashwinsh #16

Don't know if you have found it but on this page https://sitestudiodocs.acquia.com/8.0/user-guide/version-800-release-det...
It says it is a known issue and to apply a patch.

It does link to it on there.
Hope this helps anyone else with the issue when using Site Studio.
It worked for me.