core/modules/ckeditor/js/ckeditor.js | 73 ++++++++-- .../ckeditor/Plugin/editor/editor/CKEditor.php | 3 +- core/modules/edit/js/backbone.drupalform.js | 22 ++- .../editingWidgets/drupalcontenteditablewidget.js | 36 +---- .../edit/js/createjs/editingWidgets/formwidget.js | 4 +- .../edit/js/views/propertyeditordecoration-view.js | 30 +++- core/modules/edit/js/views/toolbar-view.js | 6 + .../edit/Plugin/edit/editor/DirectEditor.php | 2 +- .../Drupal/edit/Plugin/edit/editor/FormEditor.php | 2 +- .../edit/lib/Drupal/edit/Tests/EditTestBase.php | 2 +- .../Drupal/edit/Tests/MetadataGeneratorTest.php | 2 - core/modules/editor/editor.module | 4 +- core/modules/editor/js/editor.createjs.js | 144 ++++++++------------ ...Command.php => GetUntransformedTextCommand.php} | 8 +- .../editor/lib/Drupal/editor/EditorController.php | 7 +- .../Drupal/editor/Plugin/edit/editor/Editor.php | 6 +- .../Drupal/editor/Tests/EditIntegrationTest.php | 16 +-- 17 files changed, 206 insertions(+), 161 deletions(-) diff --git a/core/modules/ckeditor/js/ckeditor.js b/core/modules/ckeditor/js/ckeditor.js index b8318be..3568452 100644 --- a/core/modules/ckeditor/js/ckeditor.js +++ b/core/modules/ckeditor/js/ckeditor.js @@ -1,20 +1,11 @@ -(function (Drupal, CKEDITOR) { +(function (Drupal, drupalSettings, CKEDITOR, $) { "use strict"; Drupal.editors.ckeditor = { attach: function (element, format) { - var externalPlugins = format.editorSettings.externalPlugins; - // Register and load additional CKEditor plugins as necessary. - if (externalPlugins) { - for (var pluginName in externalPlugins) { - if (externalPlugins.hasOwnProperty(pluginName)) { - CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); - } - } - delete format.editorSettings.drupalExternalPlugins; - } + this._loadExternalPlugins(format); return !!CKEDITOR.replace(element, format.editorSettings); }, @@ -26,11 +17,69 @@ Drupal.editors.ckeditor = { } else { editor.destroy(); + element.removeAttribute('contentEditable'); } } return !!editor; + }, + + onChange: function (element, callback) { + var editor = CKEDITOR.dom.element.get(element).getEditor(); + if (editor) { + var changed = function () { + callback(editor.getData()); + }; + // @todo Make this more elegant once http://dev.ckeditor.com/ticket/9794 + // is fixed. + editor.on('key', changed); + editor.on('paste', changed); + editor.on('afterCommandExec', changed); + } + return !!editor; + }, + + attachInlineEditor: function (element, format, mainToolbarId, floatedToolbarId) { + this._loadExternalPlugins(format); + + var settings = $.extend(true, {}, format.editorSettings); + + // If a toolbar is already provided for "true WYSIWYG" (in-place editing), + // then use that toolbar instead: override the default settings to render + // CKEditor UI's top toolbar into mainToolbar, and don't render the bottom + // toolbar at all. (CKEditor doesn't need a floated toolbar.) + if (mainToolbarId) { + var settingsOverride = { + extraPlugins: 'sharedspace', + removePlugins: 'floatingspace,elementspath', + sharedSpaces: { + top: mainToolbarId + } + }; + settings.extraPlugins += ',' + settingsOverride.extraPlugins; + settings.removePlugins += ',' + settingsOverride.removePlugins; + settings.sharedSpaces = settingsOverride.sharedSpaces; + } + + // CKEditor requires an element to already have the contentEditable + // attribute set to "true", otherwise it won't attach an inline editor. + element.setAttribute('contentEditable', 'true'); + + return !!CKEDITOR.inline(element, settings); + }, + + _loadExternalPlugins: function(format) { + var externalPlugins = format.editorSettings.drupalExternalPlugins; + // Register and load additional CKEditor plugins as necessary. + if (externalPlugins) { + for (var pluginName in externalPlugins) { + if (externalPlugins.hasOwnProperty(pluginName)) { + CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); + } + } + delete format.editorSettings.drupalExternalPlugins; + } } }; -})(Drupal, CKEDITOR); +})(Drupal, drupalSettings, CKEDITOR, jQuery); diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php index e4c0948..960b3f8 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php @@ -18,7 +18,8 @@ * @Plugin( * id = "ckeditor", * label = @Translation("CKEditor"), - * module = "ckeditor" + * module = "ckeditor", + * supports_inline_editing = TRUE * ) */ class CKEditor extends EditorBase { diff --git a/core/modules/edit/js/backbone.drupalform.js b/core/modules/edit/js/backbone.drupalform.js index ba79e76..791a231 100644 --- a/core/modules/edit/js/backbone.drupalform.js +++ b/core/modules/edit/js/backbone.drupalform.js @@ -123,8 +123,7 @@ Backbone.syncDirect = function(method, model, options) { // Successfully saved. Drupal.ajax[base].commands.editFieldFormSaved = function (ajax, response, status) { - Drupal.edit.util.form.unajaxifySaving(jQuery(ajax.element)); - jQuery('#edit_backstage form').remove(); + Backbone.syncDirectCleanUp(); // Call Backbone.sync's success callback with the rerendered field. var changedAttributes = {}; @@ -161,4 +160,23 @@ Backbone.syncDirect = function(method, model, options) { } }; +/** + * Cleans up the hidden form that Backbone.syncDirect uses for syncing. + * + * This is called automatically by Backbone.syncDirect when saving is successful + * (i.e. when there are no validation errors). Only when editing is canceled + * while a PropertyEditor widget is in the invalid state, this must be called + * "manually" (in practice, ToolbarView does this). This is necessary because + * Backbone.syncDirect is not aware of the application state, it only does the + * syncing. + * An alternative could be to also remove the hidden form when validation errors + * occur, but then the form must be retrieved again, thus resulting in another + * roundtrip, which is bad for front-end performance. + */ +Backbone.syncDirectCleanUp = function() { + var $submit = jQuery('#edit_backstage form .edit-form-submit'); + Drupal.edit.util.form.unajaxifySaving($submit); + jQuery('#edit_backstage form').remove(); +}; + })(jQuery, Backbone, Drupal); diff --git a/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js b/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js index caac604..bc86a04 100644 --- a/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js +++ b/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js @@ -6,7 +6,9 @@ "use strict"; - jQuery.widget('Drupal.drupalContentEditableWidget', jQuery.Create.editWidget, { + // @todo D8: use jQuery UI Widget bridging. + // @see http://drupal.org/node/1874934#comment-7124904 + jQuery.widget('DrupalEditEditor.direct', jQuery.Create.editWidget, { /** * Implements getEditUISettings() method. @@ -54,8 +56,6 @@ if (from !== 'inactive') { // Removes the "contenteditable" attribute. this.disable(); - this._removeValidationErrors(); - this._cleanUp(); } break; case 'highlighted': @@ -70,42 +70,14 @@ case 'changed': break; case 'saving': - this._removeValidationErrors(); break; case 'saved': break; case 'invalid': break; } - }, - - /** - * Removes validation errors' markup changes, if any. - * - * Note: this only needs to happen for type=direct, because for type=direct, - * the property DOM element itself is modified; this is not the case for - * type=form. - */ - _removeValidationErrors: function() { - this.element - .removeClass('edit-validation-error') - .next('.edit-validation-errors').remove(); - }, - - /** - * Cleans up after the widget has been saved. - * - * Note: this is where the Create.Storage and accompanying Backbone.sync - * abstractions "leak" implementation details. That is only the case because - * we have to use Drupal's Form API as a transport mechanism. It is - * unfortunately a stateful transport mechanism, and that's why we have to - * clean it up here. This clean-up is only necessary when canceling the - * editing of a property after having attempted to save at least once. - */ - _cleanUp: function() { - Drupal.edit.util.form.unajaxifySaving(jQuery('#edit_backstage form .edit-form-submit')); - jQuery('#edit_backstage form').remove(); } + }); })(jQuery, Drupal); diff --git a/core/modules/edit/js/createjs/editingWidgets/formwidget.js b/core/modules/edit/js/createjs/editingWidgets/formwidget.js index 83dad4f..e7e8b69 100644 --- a/core/modules/edit/js/createjs/editingWidgets/formwidget.js +++ b/core/modules/edit/js/createjs/editingWidgets/formwidget.js @@ -6,7 +6,9 @@ "use strict"; - $.widget('Drupal.drupalFormWidget', $.Create.editWidget, { + // @todo D8: change the name to "form" + use jQuery UI Widget bridging. + // @see http://drupal.org/node/1874934#comment-7124904 + $.widget('DrupalEditEditor.formEditEditor', $.Create.editWidget, { id: null, $formContainer: null, diff --git a/core/modules/edit/js/views/propertyeditordecoration-view.js b/core/modules/edit/js/views/propertyeditordecoration-view.js index aad9832..7c3b94c 100644 --- a/core/modules/edit/js/views/propertyeditordecoration-view.js +++ b/core/modules/edit/js/views/propertyeditordecoration-view.js @@ -32,7 +32,8 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ * - editor: the editor object with an 'options' object that has these keys: * * entity: the VIE entity for the property. * * property: the predicate of the property. - * * widget: the parent EditableeEntity widget. + * * widget: the parent EditableEntity widget. + * * editorName: the name of the PropertyEditor widget * - toolbarId: the ID attribute of the toolbar as rendered in the DOM. */ initialize: function(options) { @@ -40,6 +41,7 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ this.toolbarId = options.toolbarId; this.predicate = this.editor.options.property; + this.editorName = this.editor.options.editorName; this.$el.css('background-color', this._getBgColor(this.$el)); @@ -55,6 +57,9 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ case 'inactive': if (from !== null) { this.undecorate(); + if (from === 'invalid') { + this._removeValidationErrors(); + } } break; case 'candidate': @@ -63,6 +68,9 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ this.stopHighlight(); if (from !== 'highlighted') { this.stopEdit(); + if (from === 'invalid') { + this._removeValidationErrors(); + } } } break; @@ -83,6 +91,9 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ case 'changed': break; case 'saving': + if (from === 'invalid') { + this._removeValidationErrors(); + } break; case 'saved': break; @@ -329,7 +340,24 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ else { callback(); } + }, + + /** + * Removes validation errors' markup changes, if any. + * + * Note: this only needs to happen for type=direct, because for type=direct, + * the property DOM element itself is modified; this is not the case for + * type=form. + */ + _removeValidationErrors: function() { + if (this.editorName !== 'form') { + this.$el + .removeClass('edit-validation-error') + .next('.edit-validation-errors') + .remove(); + } } + }); })(jQuery, Backbone, Drupal); diff --git a/core/modules/edit/js/views/toolbar-view.js b/core/modules/edit/js/views/toolbar-view.js index b052362..bca1351 100644 --- a/core/modules/edit/js/views/toolbar-view.js +++ b/core/modules/edit/js/views/toolbar-view.js @@ -68,6 +68,9 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ case 'inactive': if (from) { this.remove(); + if (this.editorName !== 'form') { + Backbone.syncDirectCleanUp(); + } } break; case 'candidate': @@ -75,6 +78,9 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ this.render(); } else { + if (this.editorName !== 'form') { + Backbone.syncDirectCleanUp(); + } // Remove all toolgroups; they're no longer necessary. this.$el .removeClass('edit-highlighted edit-editing') diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php b/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php index 0a386c5..b61b372 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php @@ -16,7 +16,7 @@ * * @Plugin( * id = "direct", - * jsClassName = "drupalContentEditableWidget", + * jsClassName = "direct", * module = "edit" * ) */ diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/FormEditor.php b/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/FormEditor.php index 59e8d67..f0ca366 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/FormEditor.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/FormEditor.php @@ -16,7 +16,7 @@ * * @Plugin( * id = "form", - * jsClassName = "drupalFormWidget", + * jsClassName = "formEditEditor", * module = "edit" * ) */ diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php index c3a91fb..4587ba8 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php @@ -30,7 +30,7 @@ function setUp() { $this->installSchema('system', 'variable'); $this->installSchema('field', array('field_config', 'field_config_instance')); - $this->installSchema('field_test', 'test_entity'); + $this->installSchema('field_test', array('test_entity', 'test_entity_revision')); // Set default storage backend. variable_set('field_storage_default', $this->default_storage); diff --git a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php index 529d535..61cf5ed 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php @@ -56,8 +56,6 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->installSchema('field_test', 'test_entity_revision'); - $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); $this->accessChecker = new MockEditEntityFieldAccessCheck(); $this->editorSelector = new EditorSelector($this->editorManager); diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 6cdc777..f0ad7fd 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -79,7 +79,7 @@ function editor_library_info() { ), ); // Create.js PropertyEditor widget library names begin with "edit.editor". - $libraries['edit.editor.wysiwyg'] = array( + $libraries['edit.editor.editor'] = array( 'title' => '"Editor" Create.js PropertyEditor widget', 'version' => VERSION, 'js' => array( @@ -91,7 +91,7 @@ function editor_library_info() { 'type' => 'setting', 'data' => array( 'editor' => array( - 'rerenderProcessedTextURL' => url('editor/!entity_type/!id/!field_name/!langcode/!view_mode'), + 'getUntransformedTextURL' => url('editor/!entity_type/!id/!field_name/!langcode/!view_mode'), ) ) ), diff --git a/core/modules/editor/js/editor.createjs.js b/core/modules/editor/js/editor.createjs.js index c7b1fdc..5a5ff7c 100644 --- a/core/modules/editor/js/editor.createjs.js +++ b/core/modules/editor/js/editor.createjs.js @@ -2,36 +2,45 @@ * @file * Text editor-based Create.js widget for processed text content in Drupal. * - * Depends on Editor.module. Works with any (WYSIWYG) editor that implements the - * attachInlineEditor(), detach() and onChange() methods. + * Depends on editor.module. Works with any (WYSIWYG) editor that implements the + * editor.js API, including the optional attachInlineEditor() and onChange() + * methods. + * For example, assuming that a hypothetical editor's name was "Magical Editor" + * and its editor.js API implementation lived at Drupal.editors.magical, this + * JavaScript would use: + * - Drupal.editors.magical.attachInlineEditor() + * - Drupal.editors.magical.onChange() + * - Drupal.editors.magical.detach() */ (function (jQuery, Drupal, drupalSettings) { "use strict"; - jQuery.widget('Drupal.drupalWysiwygWidget', jQuery.Create.editWidget, { + // @todo D8: use jQuery UI Widget bridging. + // @see http://drupal.org/node/1874934#comment-7124904 + jQuery.widget('DrupalEditEditor.editor', jQuery.DrupalEditEditor.direct, { textFormat: null, textFormatHasTransformations: null, textEditor: null, /** - * Implements getEditUISettings() method. + * Implements Create.editWidget.getEditUISettings. */ getEditUISettings: function () { return { padding: true, unifiedToolbar: true, fullWidthToolbar: true }; }, /** - * Implements jQuery UI widget factory's _init() method. + * Implements jQuery.widget._init. * - * @todo: POSTPONED_ON(Create.js, https://github.com/bergie/create/issues/142) - * Get rid of this once that issue is solved. + * @todo D8: Remove this. + * @see http://drupal.org/node/1874934 */ _init: function () {}, /** - * Implements Create's _initialize() method. + * Implements Create.editWidget._initialize. */ _initialize: function () { var propertyID = Drupal.edit.util.calcPropertyID(this.options.entity, this.options.property); @@ -40,58 +49,37 @@ this.textFormat = drupalSettings.editor.formats[metadata.format]; this.textFormatHasTransformations = metadata.formatHasTransformations; this.textEditor = Drupal.editors[this.textFormat.editor]; - - this._bindEvents(); - }, - - /** - * Binds to events. - */ - _bindEvents: function () { - var that = this; - - // Sets the state to 'activated' upon clicking the element. - this.element.on('click.edit', function (event) { - event.stopPropagation(); - event.preventDefault(); - that.options.activating(); - }); }, /** - * Makes this PropertyEditor widget react to state changes. + * Implements Create.editWidget.stateChange. */ stateChange: function (from, to) { var that = this; switch (to) { case 'inactive': break; + case 'candidate': - if (from !== 'inactive') { - if (from !== 'highlighted') { - this.element.attr('contentEditable', 'false'); + // Detach the text editor when entering the 'candidate' state from one + // of the states where it could have been attached. + if (from !== 'inactive' && from !== 'highlighted') { this.textEditor.detach(this.element.get(0), this.textFormat); - } - - this._removeValidationErrors(); - this._cleanUp(); - this._bindEvents(); } break; + case 'highlighted': break; + case 'activating': // When transformation filters have been been applied to the processed - // text of this field, then we'll need to load a re-rendered version of + // text of this field, then we'll need to load a re-processed version of // it without the transformation filters. if (this.textFormatHasTransformations) { - this._loadRerenderedProcessedText({ - $editorElement: this.element, - propertyID: Drupal.edit.util.calcPropertyID(this.options.entity, this.options.property), - callback: function (rerendered) { - that.element.html(rerendered); - that.options.activated(); - } + var propertyID = Drupal.edit.util.calcPropertyID(this.options.entity, this.options.property); + this._getUntransformedText(propertyID, this.element, function (untransformedText) { + that.element.html(untransformedText); + that.options.activated(); }); } // When no transformation filters have been applied: start WYSIWYG @@ -100,86 +88,68 @@ this.options.activated(); } break; + case 'active': - this.element.attr('contentEditable', 'true'); this.textEditor.attachInlineEditor( this.element.get(0), this.textFormat, this.toolbarView.getMainWysiwygToolgroupId(), this.toolbarView.getFloatedWysiwygToolgroupId() ); - - // Sets the state to 'changed' whenever the content has changed. + // Set the state to 'changed' whenever the content has changed. this.textEditor.onChange(this.element.get(0), function (html) { that.options.changed(html); }); break; + case 'changed': break; + case 'saving': - this._removeValidationErrors(); break; + case 'saved': break; + case 'invalid': break; } }, /** - * Removes validation errors' markup changes, if any. + * Loads untransformed text for a given property. * - * @todo: this should not be necessary, will be obviated by edit.module. - */ - _removeValidationErrors: function () { - this.element - .removeClass('edit-validation-error') - .next('.edit-validation-errors').remove(); - }, - - /** - * Cleans up after the widget has been saved. - * - * @todo: this should not be necessary, will be obviated by edit.module. - */ - _cleanUp: function () { - Drupal.edit.util.form.unajaxifySaving(jQuery('#edit_backstage form .edit-form-submit')); - jQuery('#edit_backstage form').remove(); - }, - - /** - * Loads rerendered processed text for a given property. + * More accurately: it re-processes processed text to exclude transformation + * filters used by the text format. * - * Leverages Drupal.ajax' ability to have scoped (per-instance) command - * implementations to be able to call a callback. + * @param String propertyID + * A property ID that uniquely identifies the given property. + * @param jQuery $editorElement + * The property's PropertyEditor DOM element. + * @param Function callback + * A callback function that will receive the untransformed text. * - * @param options - * An object with the following keys: - * - $editorElement (required): the PredicateEditor DOM element. - * - propertyID (required): the property ID that uniquely identifies the - * property for which this form will be loaded. - * - callback (required: A callback function that will receive the - * rerendered processed text. + * @see \Drupal\editor\Ajax\GetUntransformedTextCommand */ - _loadRerenderedProcessedText: function (options) { + _getUntransformedText: function (propertyID, $editorElement, callback) { // Create a Drupal.ajax instance to load the form. - Drupal.ajax[options.propertyID] = new Drupal.ajax(options.propertyID, options.$editorElement, { - url: Drupal.edit.util.buildUrl(options.propertyID, drupalSettings.editor.rerenderProcessedTextURL), + Drupal.ajax[propertyID] = new Drupal.ajax(propertyID, $editorElement, { + url: Drupal.edit.util.buildUrl(propertyID, drupalSettings.editor.getUntransformedTextURL), event: 'editor-internal.editor', submit: { nocssjs : true }, progress: { type : null } // No progress indicator. }); - // Implement a scoped editFieldRenderedWithoutTransformationFilters AJAX - // command: calls the callback. - Drupal.ajax[options.propertyID].commands.editorFieldRenderedWithoutTransformationFilters = function(ajax, response, status) { - options.callback(response.data); + // Implement a scoped editorGetUntransformedText AJAX command: calls the + // callback. + Drupal.ajax[propertyID].commands.editorGetUntransformedText = function(ajax, response, status) { + callback(response.data); // Delete the Drupal.ajax instance that called this very function. - delete Drupal.ajax[options.propertyID]; - options.$editorElement.off('editor-internal.editor'); + delete Drupal.ajax[propertyID]; + $editorElement.off('editor-internal.editor'); }; - // This will ensure our scoped editFieldRenderedWithoutTransformationFilters - // AJAX command gets called. - options.$editorElement.trigger('editor-internal.editor'); + // This will ensure our scoped editorGetUntransformedText AJAX command + // gets called. + $editorElement.trigger('editor-internal.editor'); } }); diff --git a/core/modules/editor/lib/Drupal/editor/Ajax/FieldRenderedWithoutTransformationFiltersCommand.php b/core/modules/editor/lib/Drupal/editor/Ajax/GetUntransformedTextCommand.php similarity index 53% rename from core/modules/editor/lib/Drupal/editor/Ajax/FieldRenderedWithoutTransformationFiltersCommand.php rename to core/modules/editor/lib/Drupal/editor/Ajax/GetUntransformedTextCommand.php index 77100a7..c1971d1 100644 --- a/core/modules/editor/lib/Drupal/editor/Ajax/FieldRenderedWithoutTransformationFiltersCommand.php +++ b/core/modules/editor/lib/Drupal/editor/Ajax/GetUntransformedTextCommand.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\editor\Ajax\FieldRenderedWithoutTransformationFiltersCommand. + * Contains \Drupal\editor\Ajax\GetUntransformedTextCommand. */ namespace Drupal\editor\Ajax; @@ -14,16 +14,16 @@ * AJAX command to rerender a processed text field without any transformation * filters. */ -class FieldRenderedWithoutTransformationFiltersCommand extends BaseCommand { +class GetUntransformedTextCommand extends BaseCommand { /** - * Constructs a FieldRenderedWithoutTransformationFiltersCommand object. + * Constructs a GetUntransformedTextCommand object. * * @param string $data * The data to pass on to the client side. */ public function __construct($data) { - parent::__construct('editorFieldRenderedWithoutTransformationFilters', $data); + parent::__construct('editorGetUntransformedText', $data); } } diff --git a/core/modules/editor/lib/Drupal/editor/EditorController.php b/core/modules/editor/lib/Drupal/editor/EditorController.php index 2f774fd..6e2ef76 100644 --- a/core/modules/editor/lib/Drupal/editor/EditorController.php +++ b/core/modules/editor/lib/Drupal/editor/EditorController.php @@ -2,7 +2,7 @@ /** * @file - * Contains of \Drupal\editor\EditorController. + * Contains \Drupal\editor\EditorController. */ namespace Drupal\editor; @@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\ContainerAware; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Entity\EntityInterface; -use Drupal\editor\Ajax\FieldRenderedWithoutTransformationFiltersCommand; +use Drupal\editor\Ajax\GetUntransformedTextCommand; /** * Returns responses for Editor module routes. @@ -29,6 +29,7 @@ class EditorController extends ContainerAware { * rererendered. * @param string $view_mode * The view mode the processed text field should be rerendered in. + * * @return \Drupal\Core\Ajax\AjaxResponse * The Ajax response. */ @@ -39,7 +40,7 @@ public function getUntransformedText(EntityInterface $entity, $field_name, $lang $langcode = $output['#language']; // Direct text editing is only supported for single-valued fields. $editable_text = check_markup($output['#items'][0]['value'], $output['#items'][0]['format'], $langcode, FALSE, array(FILTER_TYPE_TRANSFORM_REVERSIBLE, FILTER_TYPE_TRANSFORM_IRREVERSIBLE)); - $response->addCommand(new FieldRenderedWithoutTransformationFiltersCommand($editable_text)); + $response->addCommand(new GetUntransformedTextCommand($editable_text)); return $response; } diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/edit/editor/Editor.php b/core/modules/editor/lib/Drupal/editor/Plugin/edit/editor/Editor.php index 5aee9ef..31e12cc 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/edit/editor/Editor.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/edit/editor/Editor.php @@ -19,7 +19,7 @@ * * @Plugin( * id = "editor", - * jsClassName = "drupalWysiwygWidget", + * jsClassName = "editor", * alternativeTo = {"direct"}, * module = "editor" * ) @@ -79,7 +79,7 @@ public function getAttachments() { $manager = drupal_container()->get('plugin.manager.editor'); $definitions = $manager->getDefinitions(); - // Filter the current user's text to those that support inline editing. + // Filter the current user's formats to those that support inline editing. $formats = array(); foreach ($user_format_ids as $format_id) { $editor = editor_load($format_id); @@ -92,7 +92,7 @@ public function getAttachments() { $attachments = $manager->getAttachments($formats); // Also include editor.module's Create.js PropertyEditor widget. - $attachments['library'][] = array('editor', 'edit.editor.wysiwyg'); + $attachments['library'][] = array('editor', 'edit.editor.editor'); return $attachments; } diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php index 3dfd688..6417bd3 100644 --- a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php +++ b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\editor\Tests\EditorIntegrationTest. + * Contains \Drupal\editor\Tests\EditorIntegrationTest. */ namespace Drupal\editor\Tests; @@ -71,7 +71,7 @@ function setUp() { $this->enableModules(array('user', 'filter')); // Enable the Text Editor and Text Editor Test module. - $this->enableModules(array('editor', 'editor_test'), FALSE); + $this->enableModules(array('editor', 'editor_test')); // Create a field. $this->field_name = 'field_textarea'; @@ -122,7 +122,7 @@ protected function getSelectedEditor($items, $field_name, $view_mode = 'default' * format compatibility. */ function testEditorSelection() { - $this->editorManager = new EditorManager(); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); $this->editorSelector = new EditorSelector($this->editorManager); // Pretend there is an entity with these items for the field. @@ -146,7 +146,7 @@ function testEditorSelection() { * Tests (custom) metadata when the "Editor" Create.js editor is used. */ function testMetadata() { - $this->editorManager = new EditorManager(); + $this->editorManager = new EditorManager($this->container->getParameter('container.namespaces')); $this->accessChecker = new MockEditEntityFieldAccessCheck(); $this->editorSelector = new EditorSelector($this->editorManager); $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager); @@ -175,9 +175,9 @@ function testMetadata() { } /** - * Tests FieldRenderedWithoutTransformationFiltersCommand AJAX command. + * Tests GetUntransformedTextCommand AJAX command. */ - function testFieldRenderedWithoutTransformationFiltersCommand() { + function testGetUntransformedTextCommand() { // Create an entity with values for the field. $this->entity = field_test_create_entity(); $this->is_new = TRUE; @@ -191,10 +191,10 @@ function testFieldRenderedWithoutTransformationFiltersCommand() { $response = $controller->getUntransformedText($entity, $this->field_name, LANGUAGE_NOT_SPECIFIED, 'default'); $expected = array( array( - 'command' => 'editorFieldRenderedWithoutTransformationFilters', + 'command' => 'editorGetUntransformedText', 'data' => 'Test', ) ); - $this->assertEqual(drupal_json_encode($expected), $response->prepare($request)->getContent(), 'The FieldRenderedWithoutTransformationFiltersCommand AJAX command works correctly.'); + $this->assertEqual(drupal_json_encode($expected), $response->prepare($request)->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.'); } }