.../editingWidgets/drupalcontenteditablewidget.js | 4 +- .../edit/js/createjs/editingWidgets/formwidget.js | 4 +- core/modules/edit/js/util.js | 32 ++++++++------- .../edit/js/views/propertyeditordecoration-view.js | 14 +++---- core/modules/edit/js/views/toolbar-view.js | 29 +++++-------- core/modules/edit/lib/Drupal/edit/EditorBase.php | 10 ----- .../edit/lib/Drupal/edit/EditorInterface.php | 6 +-- .../edit/lib/Drupal/edit/EditorSelector.php | 43 ++++++++++---------- .../edit/lib/Drupal/edit/MetadataGenerator.php | 4 +- .../edit/Plugin/edit/editor/DirectEditor.php | 14 +++++-- .../Drupal/edit/Plugin/edit/editor/FormEditor.php | 15 +++++-- .../lib/Drupal/edit/Tests/EditorSelectionTest.php | 6 +-- .../Drupal/edit/Tests/MetadataGeneratorTest.php | 2 +- .../edit_test/Plugin/edit/editor/WysiwygEditor.php | 14 +++++-- 14 files changed, 99 insertions(+), 98 deletions(-) diff --git a/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js b/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js index cb59f67..5671f39 100644 --- a/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js +++ b/core/modules/edit/js/createjs/editingWidgets/drupalcontenteditablewidget.js @@ -9,9 +9,9 @@ jQuery.widget('Drupal.drupalContentEditableWidget', jQuery.Create.editWidget, { /** - * Implements getEditUiIntegration() method. + * Implements getEditUISettings() method. */ - getEditUiIntegration: function() { + getEditUISettings: function() { return { padding: true, unifiedToolbar: false, fullWidthToolbar: false }; }, diff --git a/core/modules/edit/js/createjs/editingWidgets/formwidget.js b/core/modules/edit/js/createjs/editingWidgets/formwidget.js index 511fec9..3238566 100644 --- a/core/modules/edit/js/createjs/editingWidgets/formwidget.js +++ b/core/modules/edit/js/createjs/editingWidgets/formwidget.js @@ -12,9 +12,9 @@ $formContainer: null, /** - * Implements getEditUiIntegration() method. + * Implements getEditUISettings() method. */ - getEditUiIntegration: function() { + getEditUISettings: function() { return { padding: false, unifiedToolbar: false, fullWidthToolbar: false }; }, diff --git a/core/modules/edit/js/util.js b/core/modules/edit/js/util.js index 78db78d..6633859 100644 --- a/core/modules/edit/js/util.js +++ b/core/modules/edit/js/util.js @@ -2,7 +2,7 @@ * @file * Provides utility functions for Edit. */ -(function($, Drupal, drupalSettings) { +(function($, _, Drupal, drupalSettings) { "use strict"; @@ -17,29 +17,31 @@ Drupal.edit.util.calcPropertyID = function(entity, predicate) { }; /** - * Return an aspect of the editor-specific edit UI integration. + * Retrieves a setting of the editor-specific Edit UI integration. * - * @param editor - * A create.js editor instance + * If the editor does not implement the optional getEditUISettings() method, or + * if it doesn't set a value for a certain setting, then the default value will + * be used. * - * @param aspect - * Name of the integration configuration aspect. + * @param editor + * A Create.js PropertyEditor widget instance. + * @param setting + * Name of the Edit UI integration setting. * * @return {*} */ -Drupal.edit.util.getEditUiIntegrationAspect = function(editor, aspect) { - var config = {}; - // @todo: provide this drupalSettings? - var defaultConfig = { +Drupal.edit.util.getEditUISetting = function(editor, setting) { + var settings = {}; + var defaultSettings = { padding: false, unifiedToolbar: false, fullWidthToolbar: false }; - if (typeof editor.getEditUiIntegration === 'function') { - config = editor.getEditUiIntegration(); + if (typeof editor.getEditUISettings === 'function') { + settings = editor.getEditUISettings(); } - return _.extend(defaultConfig, config)[aspect]; -} + return _.extend(defaultSettings, settings)[setting]; +}; Drupal.edit.util.buildUrl = function(id, urlFormat) { var parts = id.split('/'); @@ -173,4 +175,4 @@ Drupal.edit.util.form = { } }; -})(jQuery, Drupal, drupalSettings); +})(jQuery, _, Drupal, drupalSettings); diff --git a/core/modules/edit/js/views/propertyeditordecoration-view.js b/core/modules/edit/js/views/propertyeditordecoration-view.js index b9ccf31..0eb4e45 100644 --- a/core/modules/edit/js/views/propertyeditordecoration-view.js +++ b/core/modules/edit/js/views/propertyeditordecoration-view.js @@ -145,7 +145,7 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ }, startEdit: function() { - if (this._needsPadding()) { + if (this.getEditUISetting('padding')) { this._pad(); } }, @@ -158,20 +158,18 @@ Drupal.edit.views.PropertyEditorDecorationView = Backbone.View.extend({ // Revisit this. $('.edit-candidate').addClass('edit-editable'); - if (this._needsPadding()) { + if (this.getEditUISetting('padding')) { this._unpad(); } }, /** - * Determines whether the PropertyEditor widget needs us to add padding. + * Retrieves a setting of the editor-specific Edit UI integration. * - * @see Drupal.edit.util.getEditUiIntegrationAspect(). - * - * @return bool + * @see Drupal.edit.util.getEditUISetting(). */ - _needsPadding: function() { - return Drupal.edit.util.getEditUiIntegrationAspect(this.editor, 'padding'); + getEditUISetting: function(setting) { + return Drupal.edit.util.getEditUISetting(this.editor, setting); }, _pad: function () { diff --git a/core/modules/edit/js/views/toolbar-view.js b/core/modules/edit/js/views/toolbar-view.js index ec9b8ce..90f5db7 100644 --- a/core/modules/edit/js/views/toolbar-view.js +++ b/core/modules/edit/js/views/toolbar-view.js @@ -70,7 +70,7 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ break; case 'candidate': if (from !== 'inactive') { - if (from !== 'highlighted' && this._needsPadding()) { + if (from !== 'highlighted' && this.getEditUISetting('padding')) { this._unpad(); } this.remove(); @@ -87,14 +87,14 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ case 'active': this.startEdit(); this.setLoadingIndicator(false); - if (this.getEditUiIntegrationAspect('fullWidthToolbar')) { + if (this.getEditUISetting('fullWidthToolbar')) { this.$el.addClass('edit-toolbar-fullwidth'); } - if (this._needsPadding()) { + if (this.getEditUISetting('padding')) { this._pad(); } - if (this.getEditUiIntegrationAspect('unifiedToolbar')) { + if (this.getEditUISetting('unifiedToolbar')) { this.insertWYSIWYGToolGroups(); } break; @@ -307,21 +307,12 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ }, /** - * Determines whether the Editor needs us to add padding. + * Retrieves a setting of the editor-specific Edit UI integration. * - * @return bool + * @see Drupal.edit.util.getEditUISetting(). */ - _needsPadding: function() { - return this.getEditUiIntegrationAspect('padding'); - }, - - /** - * Retrieves an Edit UI integration aspect as defined by the editor. - * - * @see Drupal.edit.util.getEditUiIntegrationAspect(). - */ - getEditUiIntegrationAspect: function(aspect) { - return Drupal.edit.util.getEditUiIntegrationAspect(this.editor, aspect); + getEditUISetting: function(setting) { + return Drupal.edit.util.getEditUISetting(this.editor, setting); }, /** @@ -340,7 +331,7 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ var $hf = this.$el.find('.edit-toolbar-heightfaker'); $hf.css({ bottom: '6px', left: '-5px' }); - if (this.getEditUiIntegrationAspect('fullWidthToolbar')) { + if (this.getEditUISetting('fullWidthToolbar')) { $hf.css({ width: this.editor.element.width() + 10 }); } }, @@ -355,7 +346,7 @@ Drupal.edit.views.ToolbarView = Backbone.View.extend({ var $hf = this.$el.find('.edit-toolbar-heightfaker'); $hf.css({ bottom: '1px', left: '' }); - if (this.getEditUiIntegrationAspect('fullWidthToolbar')) { + if (this.getEditUISetting('fullWidthToolbar')) { $hf.css({ width: '' }); } }, diff --git a/core/modules/edit/lib/Drupal/edit/EditorBase.php b/core/modules/edit/lib/Drupal/edit/EditorBase.php index b94a50f..d2e4d09 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorBase.php +++ b/core/modules/edit/lib/Drupal/edit/EditorBase.php @@ -13,9 +13,6 @@ /** * Defines a base editor (Create.js PropertyEditor widget) implementation. - * - * This abstract class provides default implementation for the metadata and - * dynamic attachment methods, which many editors likely won't need. */ abstract class EditorBase extends PluginBase implements EditorInterface { @@ -26,11 +23,4 @@ function getMetadata(FieldInstance $instance, array $items) { return array(); } - /** - * Implements \Drupal\edit\EditorInterface::getDynamicAttachments(). - */ - function getDynamicAttachments() { - return array(); - } - } diff --git a/core/modules/edit/lib/Drupal/edit/EditorInterface.php b/core/modules/edit/lib/Drupal/edit/EditorInterface.php index d6b0950..904810b 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorInterface.php +++ b/core/modules/edit/lib/Drupal/edit/EditorInterface.php @@ -43,18 +43,18 @@ public function isCompatible(FieldInstance $instance, array $items); * The field's item values. * * @return array - * A keyed array with metadata. Each key should be prefixed with the plug-in + * A keyed array with metadata. Each key should be prefixed with the plugin * ID of the editor. */ public function getMetadata(FieldInstance $instance, array $items); /** - * Returns the dynamic (context-specific) attachments for this editor. + * Returns the attachments for this editor. * * @return array * An array of attachments, for use with #attached. * * @see drupal_process_attached() */ - public function getDynamicAttachments(); + public function getAttachments(); } diff --git a/core/modules/edit/lib/Drupal/edit/EditorSelector.php b/core/modules/edit/lib/Drupal/edit/EditorSelector.php index 964c539..8b09e80 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorSelector.php +++ b/core/modules/edit/lib/Drupal/edit/EditorSelector.php @@ -17,17 +17,24 @@ class EditorSelector implements EditorSelectorInterface { /** - * The manager for editor (Create.js PropertyEditor widget) plug-ins. + * The manager for editor (Create.js PropertyEditor widget) plugins. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ protected $editorManager; /** + * A list of alternative editor plugin IDs, keyed by editor plugin ID. + * + * @var array + */ + protected $alternatives; + + /** * Constructs a new EditorSelector. * * @param \Drupal\Component\Plugin\PluginManagerInterface - * The manager for Create.js PropertyEditor widget plug-ins. + * The manager for Create.js PropertyEditor widget plugins. */ public function __construct(PluginManagerInterface $editor_manager) { $this->editorManager = $editor_manager; @@ -37,16 +44,14 @@ public function __construct(PluginManagerInterface $editor_manager) { * Implements \Drupal\edit\EditorSelectorInterface::getEditor(). */ public function getEditor($formatter_type, FieldInstance $instance, array $items) { - $alternatives = &drupal_static(__FUNCTION__, NULL); - // Build a static cache of the editors that have registered themselves as // alternatives to a certain editor. - if (!isset($alternatives)) { + if (!isset($this->alternatives)) { $editors = $this->editorManager->getDefinitions(); foreach ($editors as $alternative_editor_id => $editor) { if (isset($editor['alternativeTo'])) { foreach ($editor['alternativeTo'] as $original_editor_id) { - $alternatives[$original_editor_id][] = $alternative_editor_id; + $this->alternatives[$original_editor_id][] = $alternative_editor_id; } } } @@ -68,8 +73,8 @@ public function getEditor($formatter_type, FieldInstance $instance, array $items // No early return, so create a list of all choices. $editor_choices = array($editor_id); - if (isset($alternatives[$editor_id])) { - $editor_choices = array_merge($editor_choices, $alternatives[$editor_id]); + if (isset($this->alternatives[$editor_id])) { + $editor_choices = array_merge($editor_choices, $this->alternatives[$editor_id]); } // Make a choice. @@ -93,15 +98,18 @@ public function getEditor($formatter_type, FieldInstance $instance, array $items */ public function getAllEditorAttachments() { $attachments = array(); - - // Static attachments: the library for each editor plus corresponding - // settings for Edit. $definitions = $this->editorManager->getDefinitions(); + + // Editor plugins' attachments. + $editor_ids = array_keys($definitions); + foreach ($editor_ids as $editor_id) { + $editor = $this->editorManager->createInstance($editor_id); + $attachments[] = $editor->getAttachments();; + } + + // JavaScript settings for Edit. foreach ($definitions as $definition) { $attachments[] = array( - 'library' => array( - array($definition['library']['module'], $definition['library']['name']) - ), // This will be used in Create.js' propertyEditorWidgetsConfiguration. 'js' => array( array( @@ -114,13 +122,6 @@ public function getAllEditorAttachments() { ); } - // Dynamic attachments. - $editor_ids = array_keys($definitions); - foreach ($editor_ids as $editor_id) { - $editor = $this->editorManager->createInstance($editor_id); - $attachments[] = $editor->getDynamicAttachments();; - } - return NestedArray::mergeDeepArray($attachments); } } diff --git a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php index 99b4ac5..29a01cb 100644 --- a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php +++ b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php @@ -33,7 +33,7 @@ class MetadataGenerator implements MetadataGeneratorInterface { protected $editorSelector; /** - * The manager for editor (Create.js PropertyEditor widget) plug-ins. + * The manager for editor (Create.js PropertyEditor widget) plugins. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ @@ -47,7 +47,7 @@ class MetadataGenerator implements MetadataGeneratorInterface { * @param \Drupal\edit\EditorSelectorInterface $editor_selector * An object that determines which editor to attach to a given field. * @param \Drupal\Component\Plugin\PluginManagerInterface - * The manager for editor plug-ins. + * The manager for editor plugins. */ public function __construct(EditEntityFieldAccessCheckInterface $access_checker, EditorSelectorInterface $editor_selector, PluginManagerInterface $editor_manager) { $this->accessChecker = $access_checker; 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 304dba4..0a386c5 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 @@ -17,10 +17,6 @@ * @Plugin( * id = "direct", * jsClassName = "drupalContentEditableWidget", - * library = { - * "module" = "edit", - * "name" = "edit.editor.direct" - * }, * module = "edit" * ) */ @@ -48,4 +44,14 @@ function isCompatible(FieldInstance $instance, array $items) { } } + /** + * Implements \Drupal\edit\EditorInterface::getAttachments(). + */ + public function getAttachments() { + return array( + 'library' => array( + array('edit', 'edit.editor.direct'), + ), + ); + } } 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 aa08ae5..59e8d67 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 @@ -17,10 +17,6 @@ * @Plugin( * id = "form", * jsClassName = "drupalFormWidget", - * library = { - * "module" = "edit", - * "name" = "edit.editor.form" - * }, * module = "edit" * ) */ @@ -33,4 +29,15 @@ function isCompatible(FieldInstance $instance, array $items) { return TRUE; } + /** + * Implements \Drupal\edit\EditorInterface::getAttachments(). + */ + public function getAttachments() { + return array( + 'library' => array( + array('edit', 'edit.editor.form'), + ), + ); + } + } diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php index a0305fe..199a525 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php @@ -16,7 +16,7 @@ class EditorSelectionTest extends EditTestBase { /** - * The manager for editor (Create.js PropertyEditor widget) plug-ins. + * The manager for editor (Create.js PropertyEditor widget) plugins. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ @@ -102,8 +102,8 @@ function testText() { /** * Tests a textual field, with text processing, with cardinality 1 and >1, - * always with a ProcessedTextEditor plug-in present, but with varying text - * format compatibility. + * always with an Editor plugin present that supports textual fields with text + * processing, but with varying text format compatibility. */ function testTextWysiwyg() { // Enable edit_test module so that the 'wysiwyg' Create.js PropertyEditor diff --git a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php index 9b2ee88..17bc891 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php @@ -18,7 +18,7 @@ class MetadataGeneratorTest extends EditTestBase { /** - * The manager for editor (Create.js PropertyEditor widget) plug-ins. + * The manager for editor (Create.js PropertyEditor widget) plugins. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ diff --git a/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php b/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php index fa54bea..943848f 100644 --- a/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php +++ b/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php @@ -18,10 +18,6 @@ * id = "wysiwyg", * jsClassName = "not needed for test", * alternativeTo = {"direct"}, - * library = { - * "module" = "edit_test", - * "name" = "non-existing-wysiwyg" - * }, * module = "edit_test" * ) */ @@ -58,4 +54,14 @@ function getMetadata(FieldInstance $instance, array $items) { return $metadata; } + /** + * Implements \Drupal\edit\EditorInterface::getAttachments(). + */ + public function getAttachments() { + return array( + 'library' => array( + array('edit_test', 'not-existing-wysiwyg'), + ), + ); + } }