Commit 4161b814 authored by Dave Reid's avatar Dave Reid

Issue #2544018 by Dave Reid: Disable the 'Edit Entity' contextual menu if the...

Issue #2544018 by Dave Reid: Disable the 'Edit Entity' contextual menu if the embedded entity was not embedded using a valid button.
parent 8b3ff6f3
......@@ -27,8 +27,8 @@
// Generic command for adding/editing entities of all types.
editor.addCommand('editdrupalentity', {
allowedContent: 'drupal-entity[data-entity-type,data-entity-id,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]',
requiredContent: 'drupal-entity[data-entity-type,data-entity-id,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]',
allowedContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-id,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]',
requiredContent: 'drupal-entity[data-embed-button,data-entity-type,data-entity-id,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]',
modes: { wysiwyg : 1 },
canUndo: true,
exec: function (editor, data) {
......@@ -156,7 +156,7 @@
});
editor.contextMenu.addListener(function(element) {
if (isEmbeddedEntityWidget(editor, element)) {
if (isEditableEntityWidget(editor, element)) {
return { drupalentity: CKEDITOR.TRISTATE_OFF };
}
});
......@@ -166,7 +166,7 @@
editor.on('doubleclick', function (evt) {
var element = getSelectedEmbeddedEntity(editor) || evt.data.element;
if (isEmbeddedEntityWidget(editor, element)) {
if (isEditableEntityWidget(editor, element)) {
editor.execCommand('editdrupalentity');
}
});
......@@ -181,7 +181,7 @@
function getSelectedEmbeddedEntity(editor) {
var selection = editor.getSelection();
var selectedElement = selection.getSelectedElement();
if (isEmbeddedEntityWidget(editor, selectedElement)) {
if (isEditableEntityWidget(editor, selectedElement)) {
return selectedElement;
}
......@@ -189,14 +189,25 @@
}
/**
* Returns whether or not the given element is a drupalentity widget.
* Checks if the given element is an editable drupalentity widget.
*
* @param {CKEDITOR.editor} editor
* @param {CKEDITOR.htmlParser.element} element
*/
function isEmbeddedEntityWidget (editor, element) {
function isEditableEntityWidget (editor, element) {
var widget = editor.widgets.getByElement(element, true);
return widget && widget.name === 'drupalentity';
if (!widget || widget.name !== 'drupalentity') {
return false;
}
var button = $(element.$.firstChild).attr('data-embed-button');
if (!button) {
// If there was no data-embed-button attribute, not editable.
return false;
}
// The button itself must be valid.
return editor.config.DrupalEntity_buttons.hasOwnProperty(button);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment