DrupalImageCaption plugin does not recognize <img src>, with a manually specified src

Created on 26 October 2016, about 8 years ago
Updated 27 February 2023, over 1 year ago

The image caption plugin works fine with images uploaded through the plugin, but breaks for images given as url (local or remote).
(It also breaks for older, existing images, but that's another issue :P)

When creating content the plugin can handle remote images too, but when editing the content the widget is not recognized.

How to reproduce:

- Turn on the image caption plugin for a ckeditor enabled input format while having the image upload function disabled.
- Create some content, insert an image using an url and enable caption.
- Save, then edit the content.

Expected behaviour:

The image is recognized as the widget image with caption and behaves like one (caption editable, image button opens dialog with the image data in it)

Actual behaviour:

The image is not recognized by ckeditor as an image with caption and can not be interacted with as such.

Proposed solution:

This seems to be the line (drupalimagecaption/plugin.js@112) causing the issue and removing those attribute checks seems to solve it.

var originalUpcast = widgetDefinition.upcast;
        widgetDefinition.upcast = function (element, data) {
//          if (element.name !== 'img' || !element.attributes['data-entity-type'] || !element.attributes['data-entity-uuid']) {
          if (element.name !== 'img') {
            return;
          }

Any particular reason why those checks were there?

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary karol haltenberger

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024