Links around media images break when edited, using Linkit and CKeditor

Created on 13 July 2020, over 4 years ago
Updated 16 May 2024, 6 months ago

I'm getting the following error on drupal 9.0.2 but also tested on a could of D8 sites. When trying to make a media image a link the following error happens upon saving the page:

Drupal\Core\Entity\EntityStorageException: The "" entity type does not exist. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 810 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Entity\EntityRepository->loadEntityByUuid('', '') (Line: 31)
Drupal\entity_usage\Plugin\EntityUsage\Track\TextFieldEmbedBase->getTargetEntities(Object) (Line: 148)
Drupal\entity_usage\EntityUsageTrackBase->trackOnEntityCreation(Object) (Line: 171)
Drupal\entity_usage\EntityUsageTrackBase->trackOnEntityUpdate(Object) (Line: 107)
Drupal\entity_usage\EntityUpdateManager->trackUpdateOnEdition(Object) (Line: 41)
entity_usage_entity_update(Object)

Steps to recreate:
1) Add an image using the ckeditor media icon and it goes into the editor link something like:
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="04da50f3-73da-4319-9227-89c2a87fbf89"></drupal-media>

2) Make the media item a link to https://google.com and now shows as:

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

3) Edit the link for the media item by right clicking and click "edit link" (or reclick the link icon). Change something about the link or don't change anything and just click save. The link now shows as:

<a class="" data-entity-substitution="" data-entity-type="" data-entity-uuid="" href="https://google.com" id="" rel="" target="" title="">
<drupal-media data-align="center" data-entity-type="media" data-entity-uuid="04da50f3-73da-4319-9227-89c2a87fbf89"></drupal-media>
</a>

So it's added all these empty data attributes (data-entity-substitution="" data-entity-type="" data-entity-uuid=""). I assume its something to do with the media short code being rendered into the actual media article that's adding these empty attributes. Normally if linking to an entity those values would be populated with that entities info. But when editing to something else e.g. an external site the go in empty and cause that error mentioned above.

Its a fairly major issue as it means content editors can't ever edit a link. A am using the linkit module but I'm not sure if its core that's adding these data attributes or core functionality at the moment

πŸ› Bug report
Status

Postponed: needs info

Version

7.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom maseyuk

Live updates comments and jobs are added and updated live.
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