diff --git a/src/bundle/Resources/public/js/CKEditor/embed/image/embed-image-editing.js b/src/bundle/Resources/public/js/CKEditor/embed/image/embed-image-editing.js index 72f28202..c0ea8c18 100644 --- a/src/bundle/Resources/public/js/CKEditor/embed/image/embed-image-editing.js +++ b/src/bundle/Resources/public/js/CKEditor/embed/image/embed-image-editing.js @@ -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 { @@ -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, }); } @@ -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); }