In CKEditor 5, I use media in my nodes. I've got a big problem. When I click on the media while editing the node, it opens the file.

I want the media to be linked to the file only when the node is displayed, not in the form of the node.

In CKEditor 5 how not to link media to file, in node editing?

More use cases for linked media within CKeditor 5 are embedding documents, videos, and audio that are all interactive. I'm not sure the media module is the correct place to address whether media is clickable within the text editor. Right now the touch target for showing the contextual toolbar on a media item is a thin line around the image, document, video, etc. If you miss that line and click the media, you get one of two experiences:

Unlinked Media

If the media is an image without a configured linked display, you get the contextual media toolbar.

Screentshot of clicking on an embedded image media item.

This is pretty much what an editor would expect.

Linked Media

If the media is a remote video, clicking on the media will play the video.

Screenshot of clicking on an embedded remote video media item.

If the media is a document, clicking on the media will download the document.

Screenshot of clicking on an embedded document media item.

Issue fork drupal-3326455

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

zenimagine created an issue. See original summary.

zenimagine’s picture

This behavior is weird and unintuitive. If the author presses the image without having made a backup, he loses his writing. In CKEditor this should be configurable. Same problem to display the parameters of the image, you have to click next to it and play with the arrows on the keyboard. If I click on the image to display the parameters, it displays the file. Do you find it logical and intuitive ?

zenimagine’s picture

Version: 9.4.x-dev » 9.5.x-dev
Component: media system » ckeditor5.module
Category: Support request » Task
zenimagine’s picture

It is necessary to add in the configuration of CKEditor 5 if the image must be linked to the file or not.

When I click on the image, I want to see the image configuration menu appear, not the file.

wim leers’s picture

Title: In CKEditor 5 how not to link the media to the file ? » [drupalMedia] When media is embedded in a view mode whose display is configured to link elsewhere, that link should not be clickable in CKEditor
Category: Task » Bug report
Issue tags: +JavaScript, +Needs tests, +Needs issue summary update

Thanks for the detailed bug report, @zenimagine! 👏

Default core/profiles/standard/config/optional/core.entity_view_display.media.image.default.yml config:

langcode: en
status: true
dependencies:
  config:
    - field.field.media.image.field_media_image
    - image.style.large
    - media.type.image
  module:
    - image
id: media.image.default
targetEntityType: media
bundle: image
mode: default
content:
  field_media_image:
    type: image
    label: visually_hidden
    settings:
      image_style: 'large'
      image_link: ''
      image_loading:
        attribute: lazy
    third_party_settings: {  }
    weight: 1
    region: content
hidden:
  created: true
  thumbnail: true
  uid: true
  name: true

Note how image_link: '' means that image media are not linked by default in this view mode. But you can change this to image_link: content or image_link: file, in which case this will be linked.

In that case, it's indeed possible to click the image media and the link will be followed.

Given this is non-standard configuration, I don't think this qualifies as Major, but it definitely is something that should be fixed.

Having read https://git.drupalcode.org/project/ckeditor/-/blob/1.0.x/js/plugins/drup..., I'm not sure CKEditor 4 protected against this either. We need to check that. If it worked correctly there, then this would be a regression.

@zenimagine: any chance you could check that? 😊🙏

zenimagine’s picture

Do you have a patch to disable photo links in CKEditor, when editing a node ?

wim leers’s picture

No, I haven't worked on a patch yet.

zenimagine’s picture

I have an image media type. I would like to display the image and the link to the file in the rendered Media. I don't want the image to be a link to the file.

I couldn't find a link to the file field in *Manage display*. I looked at the media.html.twig file, but I could not understand how to link to the file.

How can I add the media file link in *Manage display*?

{#
/**
 * @file
 * Default theme implementation to present a media item.
 *
 * Available variables:
 * - media: The media item, with limited access to object properties and
 *   methods. Only method names starting with "get", "has", or "is" and
 *   a few common methods such as "id", "label", and "bundle" are available.
 *   For example:
 *   - entity.getEntityTypeId() will return the entity type ID.
 *   - entity.hasField('field_example') returns TRUE if the entity includes
 *     field_example. (This does not indicate the presence of a value in this
 *     field.)
 *   Calling other methods, such as entity.delete(), will result in
 *   an exception.
 *   See \Drupal\Core\Entity\EntityInterface for a full list of methods.
 * - name: Name of the media item.
 * - content: Media content.
 * - title_prefix: Additional output populated by modules, intended to be
 *   displayed in front of the main title tag that appears in the template.
 * - title_suffix: Additional output populated by modules, intended to be
 *   displayed after the main title tag that appears in the template.
 * - view_mode: View mode; for example, "teaser" or "full".
 * - attributes: HTML attributes for the containing element.
 * - title_attributes: Same as attributes, except applied to the main title
 *   tag that appears in the template.
 *
 * @see template_preprocess_media()
 *
 * @ingroup themeable
 */
#}
<div{{ attributes }}>
  {{ title_suffix.contextual_links }}
  {{ content }}
</div>
wim leers’s picture

That is a question for the media system component, not for ckeditor5.module. I don't know the answer 😇

I do acknowledge that the CKEditor 5 "media rendered with wrapping link" entity view display configuration is broken in CKEditor 5, that will be handled here 👍

joelpittet’s picture

Issue tags: -JavaScript +JavaScript

I was about to create this issue, glad it's here, ran into it when testing variations out #3348603: CKEditor 5 resizes images with % width instead of px width (the CKEditor 4 default): breaks image captions *and* is a regression Though not related to that issue I thought I'd reference it here for completeness.

lauriii’s picture

Issue tags: +Usability
joshuami’s picture

Issue summary: View changes
StatusFileSize
new257.62 KB
new263.75 KB
new266.14 KB

The improvements to images embedded via CKeditor 5 are impressive, but all other media types suffer a little bit from an upgrade to CKeditor 5.

More use cases for linked media within CKeditor 5 are embedding documents, videos, and audio that are all interactive. I'm not sure the media module is the correct place to address whether media is clickable within the text editor. Right now the touch target for showing the contextual toolbar on a media item is a thin line around the image, document, video, etc. If you miss that line and click the media, you get one of two experiences:

Unlinked Media

If the media is an image without a configured linked display, you get the contextual media toolbar.

Screentshot of clicking on an embedded image media item.

This is pretty much what an editor would expect.

Linked Media

If the media is a remote video, clicking on the media will play the video.

Screenshot of clicking on an embedded remote video media item.

If the media is a document, clicking on the media will download the document.

Screenshot of clicking on an embedded document media item.

For any media type other than image, the loss of an "edit media" button that has a decent touch target is a huge loss. The loss of an embed dialog that allows you to configure and possibly replace the media seems to also be the result of only looking at media management from an image perspective and not considering the embed complexities for other media types.

It would be a better experience, if a user could interact with a preview of the media entity where the entire embedded item is a trigger for the contextual toolbar. This would be similar to the link contextual toolbar which opens when you click the link rather than taking you to the link destination.

Updating the issue summary with the additional use cases.

el7cosmos’s picture

we should emulate demo in https://ckeditor.com/docs/ckeditor5/latest/features/media-embed.html#demo, clicking the media won't playing the video.

el7cosmos’s picture

It seems pointer-events: none css rule do the tricks

el7cosmos’s picture

Status: Active » Needs review
smustgrave’s picture

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

Ran the test without the first to make sure it failed and got

1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testMediaPointerEvent
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://drupal-10.x.ddev.site/node/1/edit'
+'http://drupal-10.x.ddev.site/sites/simpletest/34354334/files/image-test.png'

/var/www/html/web/vendor/phpunit/phpunit/src/Framework/Constraint/Equality/IsEqual.php:96
/var/www/html/web/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php:1687
/var/www/html/web/vendor/phpunit/phpunit/src/Framework/TestResult.php:728

Which is good so I'll remove that tag.

#6 was tagged for an issue summary update if that could happen next please.

lauriii’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
StatusFileSize
new1.72 KB

I think the issue summary is fine as of #13. At least I was able to figure out what this issue is about based on that.

joshuami’s picture

Status: Needs review » Reviewed & tested by the community

Just tested on a Drupal 10.1 site with the patch against a remote video and a document embed. In both cases, clicking the media item triggers the tooltip instead of triggering the interaction with the media item (playing the video or downloading the document).

Thanks for jumping in on this one @lauriii!

  • lauriii committed d80291c2 on 11.x
    Issue #3326455 by el7cosmos, lauriii, joshuami, zenimagine, Wim Leers,...

  • lauriii committed d75fdb1f on 10.1.x
    Issue #3326455 by el7cosmos, lauriii, joshuami, zenimagine, Wim Leers,...
lauriii’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed d80291c and pushed to 11.x. Thanks! Also cherry-picked to 10.1.x since this is a bug fix.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.