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 simply adding a link to a Drupal Media item 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. Strangely, the "change" event is correctly fired when adding a link to a Drupal Image item.

Steps to reproduce

  1. Edit a node with a body field that uses CKEditor with the Drupal Media CKEditor plugin enabled.
  2. Add media to your content.
  3. Save the node, then go back to the edit screen.
  4. Click on the Drupal Media item, then click the link icon in the CKEditor toolbar and add a link to wrap the media item.
  5. Use the code inspector to inspect the accompanying, hidden textarea (its name will be "body[0][value]").
  6. The "data-editor-value-is-changed" attribute should be "true", but is not.
  7. Make any other changes to content -- add a line break, add some text, etc.
  8. Inspect the textarea again. The "data-editor-value-is-changed" is now correctly set to "true".

Proposed resolution

Add code to the Drupal Media CKEditor plugin to correctly fire the "change" event when the link value is changed.

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-3275613

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

Component: ckeditor.module » media system

justin2pin’s picture

Issue tags: +Needs tests
justin2pin’s picture

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

Includes tests, added to CKEditorIntegrationTest::testLinkability. Ready for review.

joelsteidl’s picture

Having recently hit this bug, I can confirm that this patch solves the issue.

Previously the only way to get adding or removing a link from a media item to work would be to change some text in the WYSIWYG, which I imagine would fire data-editor-value-is-changed attribute.

I can now simply add or remove a link to a media item and my change is registered correctly.

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.

sudesh.solaskar’s picture

@justin2pun and @joelsteidl the MR is not working on drupal 9.3.17. Thew patch is getting applied successfully but when i add link to media item it does not work

smustgrave’s picture

Status: Needs review » Needs work

The files in the MR no longer exist in Drupal 9.5. So the relevant code should updated not sure what files it moved to.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Closing the old MR for 9.4

Wonder if this is still a problem in D11? Not seeing it myself.

acbramley’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I tried adding the assertions to the new test for this same functionality in CKE5 but it passed so it does seem like this may be fixed.

As it's been over 3 months since #13 I'm going to close this out, but if it is still reproducible feel free to reopen and add the steps to the IS starting from Install Drupal.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.