core/modules/edit/js/edit.js | 2 +- core/modules/edit/js/models/EntityModel.js | 6 +++- core/modules/edit/js/views/AppView.js | 8 +++--- core/modules/edit/js/views/EntityToolbarView.js | 30 ++++++++++---------- .../edit/lib/Drupal/edit/MetadataGenerator.php | 11 ++++--- .../lib/Drupal/edit/MetadataGeneratorInterface.php | 13 ++++++++- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/core/modules/edit/js/edit.js b/core/modules/edit/js/edit.js index f6fdadd..1d618a6 100644 --- a/core/modules/edit/js/edit.js +++ b/core/modules/edit/js/edit.js @@ -314,7 +314,7 @@ function initializeEntityContextualLink (contextualLink) { var entityModel = new Drupal.edit.EntityModel({ el: contextualLink.region, id: contextualLink.entityID, - title: Drupal.edit.metadata.get(contextualLink.entityID, 'title') + label: Drupal.edit.metadata.get(contextualLink.entityID, 'label') }); Drupal.edit.collections.entities.add(entityModel); diff --git a/core/modules/edit/js/models/EntityModel.js b/core/modules/edit/js/models/EntityModel.js index 5d1ea9f..52b4d22 100644 --- a/core/modules/edit/js/models/EntityModel.js +++ b/core/modules/edit/js/models/EntityModel.js @@ -14,6 +14,8 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ el: null, // An entity ID, of the form "/", e.g. "node/1". id: null, + // The label of the entity. + label: null, // A Drupal.edit.FieldCollection for all fields of this entity. fields: null, @@ -26,7 +28,9 @@ Drupal.edit.EntityModel = Backbone.Model.extend({ // isDirty: false, // The current processing state of an entity. - state: 'inactive' + state: 'inactive', + // @see AppView.appStateChange() + entityToolbar: null }, /** diff --git a/core/modules/edit/js/views/AppView.js b/core/modules/edit/js/views/AppView.js index c1523b8..92ee704 100644 --- a/core/modules/edit/js/views/AppView.js +++ b/core/modules/edit/js/views/AppView.js @@ -1,4 +1,4 @@ -(function ($, _, Backbone, Drupal) { +(function ($, _, Backbone, Drupal, drupalSettings) { "use strict"; @@ -284,7 +284,7 @@ Drupal.edit.AppView = Backbone.View.extend({ var $el = $(event.target); // This is the span element inside the button. // Create a Drupal.ajax instance to load the form. Drupal.ajax[id] = new Drupal.ajax(id, $el, { - url: '/edit/entity/' + entityModel.id, + url: drupalSettings.basePath + 'edit/entity/' + entityModel.id, event: 'edit-save.edit', progress: { type: 'none' @@ -298,7 +298,7 @@ Drupal.edit.AppView = Backbone.View.extend({ // Entity saved successfully. Drupal.ajax[id].commands.editEntitySaved = function(ajax, response, status) { // Remove the changed marker from all of the fields. - that.fieldsCollection.each(function (fieldModel) { + entityModel.get('fields').each(function (fieldModel) { $(fieldModel.get('el')).find('.edit-editable').addBack().removeClass('edit-changed'); }); // Reset the list tracking changed fields. @@ -574,4 +574,4 @@ Drupal.edit.AppView = Backbone.View.extend({ } }); -}(jQuery, _, Backbone, Drupal)); +}(jQuery, _, Backbone, Drupal, drupalSettings)); diff --git a/core/modules/edit/js/views/EntityToolbarView.js b/core/modules/edit/js/views/EntityToolbarView.js index bb9f00c..9918d97 100644 --- a/core/modules/edit/js/views/EntityToolbarView.js +++ b/core/modules/edit/js/views/EntityToolbarView.js @@ -18,12 +18,12 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ 'click.edit button.action-save': 'onClickSave', 'click.edit button.action-cancel': 'onClickClose', 'mouseenter.edit': 'onMouseenter' - } + }; return map; }, /** - * Implements Backbone.View.prototype.initialize(). + * {@inheritdoc} */ initialize: function (options) { var that = this; @@ -54,7 +54,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ }, /** - * Implements Backbone.View.prototype.render(). + * {@inheritdoc} */ render: function (model, changeValue) { @@ -75,7 +75,7 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ this.remove(); } - var $save = this.$el.find('.edit-button.action-save') + var $save = this.$el.find('.edit-button.action-save'); $save.attr('aria-hidden', !this.model.get('isDirty')); // The progress spinner will only be set when the save button is clicked. // Remove it on any call to render. @@ -111,12 +111,12 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ var edge = (document.documentElement.dir === 'rtl') ? 'right' : 'left'; // If a field in this entity is active, position against it. var activeEditor = Drupal.edit.app.model.get('activeEditor'); - var activeEkditorView = activeEditor && activeEditor.get('editorView'); - var activeEditedElement = activeEkditorView && activeEkditorView.getEditedElement(); + var activeEditorView = activeEditor && activeEditor.editorView; + var activeEditedElement = activeEditorView && activeEditorView.getEditedElement(); // Label of a highlighted field, if it exists. var highlightedEditor = Drupal.edit.app.model.get('highlightedEditor'); - var highlightedEditorView = highlightedEditor && highlightedEditor.get('editorView'); + var highlightedEditorView = highlightedEditor && highlightedEditor.editorView; var highlightedEditedElement = highlightedEditorView && highlightedEditorView.getEditedElement(); // Prefer the specified element from the parameters, then the acive field // and finally the entity itself to determine the position of the toolbar. @@ -293,25 +293,25 @@ Drupal.edit.EntityToolbarView = Backbone.View.extend({ }, /** - * + * Generates a state-dependent label for the entity toolbar. */ label: function () { - // The entity title. - var title = this.model.get('title'); + // The entity label. + var label = '"' + this.model.get('label') + '"'; // Label of an active field, if it exists. var activeEditor = Drupal.edit.app.model.get('activeEditor'); - var activeFieldLabel = activeEditor && activeEditor.get('label'); - activeFieldLabel = activeFieldLabel && activeFieldLabel + '::' + title; + var activeFieldLabel = activeEditor && activeEditor.get('metadata').label; + activeFieldLabel = activeFieldLabel && activeFieldLabel + ' — ' + label; // Label of a highlighted field, if it exists. var highlightedEditor = Drupal.edit.app.model.get('highlightedEditor'); - var highlightedFieldLabel = highlightedEditor && highlightedEditor.get('label'); - highlightedFieldLabel = highlightedFieldLabel && highlightedFieldLabel + '::' + title; + var highlightedFieldLabel = highlightedEditor && highlightedEditor.get('metadata').label; + highlightedFieldLabel = highlightedFieldLabel && highlightedFieldLabel + ' — ' + label; this.$el .find('.edit-toolbar-label') - .text(activeFieldLabel || highlightedFieldLabel || title); + .text(activeFieldLabel || highlightedFieldLabel || label); }, /** diff --git a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php index 5f7e41b..5492914 100644 --- a/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php +++ b/core/modules/edit/lib/Drupal/edit/MetadataGenerator.php @@ -55,17 +55,17 @@ public function __construct(EditEntityFieldAccessCheckInterface $access_checker, $this->editorManager = $editor_manager; } + /** + * {@inheritdoc} + */ public function generateEntity(EntityInterface $entity, $langcode) { - $title = $entity->getTranslation($langcode, FALSE)->get('title')->getValue(); - $title = $title[0]['value']; return array( - 'type' => 'entity', - 'title' => $title + 'label' => $entity->label($langcode), ); } /** - * Implements \Drupal\edit\MetadataGeneratorInterface::generate(). + * {@inheritdoc} */ public function generateField(EntityInterface $entity, FieldInstance $instance, $langcode, $view_mode) { $field_name = $instance['field_name']; @@ -88,7 +88,6 @@ public function generateField(EntityInterface $entity, FieldInstance $instance, $label = $instance['label']; $editor = $this->editorManager->createInstance($editor_id); $metadata = array( - 'type' => 'field', 'label' => check_plain($label), 'access' => TRUE, 'editor' => $editor_id, diff --git a/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php b/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php index d785171..6d60f33 100644 --- a/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php +++ b/core/modules/edit/lib/Drupal/edit/MetadataGeneratorInterface.php @@ -11,10 +11,21 @@ use Drupal\field\Plugin\Core\Entity\FieldInstance; /** - * Interface for generating in-place editing metadata for an entity field. + * Interface for generating in-place editing metadata. */ interface MetadataGeneratorInterface { + /** + * Generates in-place editing metadata for an entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity being edited. + * @param string $langcode + * The name of the language for which the field is being edited. + * @return array + * An array containing metadata with the following keys: + * - label: the user-visible label for the entity. + */ public function generateEntity(EntityInterface $entity, $langcode); /**