Skip to content

Commit

Permalink
IBX-9326: The image link with a class is producing an error.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabowskiM committed Dec 16, 2024
1 parent 640419c commit a7d774a
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Widget from '@ckeditor/ckeditor5-widget/src/widget';

import IbexaEmbedImageCommand from './embed-image-command';

import { getCustomClassesConfig } from '../../custom-attributes/helpers/config-helper';
import { findContent } from '../../services/content-service';

class IbexaEmbedImageEditing extends Plugin {
Expand Down Expand Up @@ -70,11 +71,17 @@ class IbexaEmbedImageEditing extends Plugin {

defineSchema() {
const { schema } = this.editor.model;
const customClassesConfig = getCustomClassesConfig();
const allowedAttributes = ['contentId', 'size', 'ibexaLinkHref', 'ibexaLinkTitle', 'ibexaLinkTarget'];

if (customClassesConfig.link) {
allowedAttributes.push('ibexaLinkClasses');
}

schema.register('embedImage', {
isObject: true,
allowWhere: '$block',
allowAttributes: ['contentId', 'size', 'ibexaLinkHref', 'ibexaLinkTitle', 'ibexaLinkTarget'],
allowAttributes: allowedAttributes,
});
}

Expand Down Expand Up @@ -153,17 +160,28 @@ class IbexaEmbedImageEditing extends Plugin {
downcastWriter.insert(downcastWriter.createPositionAt(container, 0), config);

if (linkHref) {
const link = downcastWriter.createUIElement('a', {
const linkClasses = modelElement.getAttribute('ibexaLinkClasses');
const linkAttributes = {
'data-ezelement': 'ezlink',
href: linkHref,
title: modelElement.getAttribute('ibexaLinkTitle'),
target: modelElement.getAttribute('ibexaLinkTarget'),
});
};

if (linkClasses) {
linkAttributes.class = linkClasses;
}

const link = downcastWriter.createUIElement('a', linkAttributes);

consumable.consume(modelElement, 'attribute:ibexaLinkHref');
consumable.consume(modelElement, 'attribute:ibexaLinkTitle');
consumable.consume(modelElement, 'attribute:ibexaLinkTarget');

if (linkClasses) {
consumable.consume(modelElement, 'attribute:ibexaLinkClasses');
}

downcastWriter.insert(downcastWriter.createPositionAt(container, 'end'), link);
}

Expand Down

0 comments on commit a7d774a

Please sign in to comment.