Links surrounding Media Library item strips data-entity-type and data-entity-uuid

Created on 23 October 2023, about 1 year ago
Updated 15 May 2024, 6 months ago

When trying to make Drupal Media entity wrapped with a link, the <a> is inserted around the media entity markup, but the markup omits data-entity-type, data-entity-uuid and data-entity-substitution attributes on the <a> tag. This prevents the link from rendering anything other than the internal URL.

Steps to recreate

1. Add an image in CKEditor using the Drupal media icon.
2. It will insert something like this:
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="04da50f3-73da-4319-9227-89c2a87fbf89"></drupal-media>
3. Focus selection on the media entity and click the Drupal link icon, attempting to insert any URL (internal or external).

Expected output

<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="1230-2349879234-2349823749" href="https://google.com">
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="04da50f3-73da-4319-9227-89c2a87fbf89"></drupal-media>
</a>

Actual output

<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="1230-2349879234-2349823749" href="https://google.com">
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="04da50f3-73da-4319-9227-89c2a87fbf89"></drupal-media>
</a>

Root cause

The method _addExtraAttributesOnLinkCommandExecute() in linkitediting.js attempts add these attributes to the "selection." In the case of the Drupal media entity being the selection, const ranges = model.schema.getValidRanges(selection.getRanges(), attribute); results in a null object and the attributes are not added.

💬 Support request
Status

Postponed

Version

7.0

Component
CKEditor 5 

Last updated 1 day ago

Created by

🇹🇳Tunisia mehdib4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024