Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-9326: The image link with a class is producing an error. #201

Draft
wants to merge 1 commit into
base: 4.6
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading