Commit 08715442 authored by webchick's avatar webchick

Issue #2133869 by Wim Leers: Clean up Edit's data- attributes.

parent b810cf1d
...@@ -36,10 +36,11 @@ function hook_edit_editor_alter(&$editors) { ...@@ -36,10 +36,11 @@ function hook_edit_editor_alter(&$editors) {
* following in-place editing in the exact way it was displayed originally), * following in-place editing in the exact way it was displayed originally),
* implement this hook. * implement this hook.
* *
* Edit module integrates with HTML elements with data-edit-id attributes. For * Edit module integrates with HTML elements with data-edit-field-id attributes.
* example: data-edit-id="node/1/<field-name>/und/<module-name>-<custom-id>". * For example:
* data-edit-field-id="node/1/<field-name>/und/<module-name>-<custom-id>"
* After the editing is complete, this hook is invoked on the module with * After the editing is complete, this hook is invoked on the module with
* the custom render pipeline identifier (last part of data-edit-id) to * the custom render pipeline identifier (last part of data-edit-field-id) to
* re-render the field. Use the same logic used when rendering the field for * re-render the field. Use the same logic used when rendering the field for
* the original display. * the original display.
* *
......
...@@ -182,7 +182,7 @@ function edit_preprocess_field(&$variables) { ...@@ -182,7 +182,7 @@ function edit_preprocess_field(&$variables) {
// fields") and computed fields are not editable. // fields") and computed fields are not editable.
$definition = $entity->getPropertyDefinition($element['#field_name']); $definition = $entity->getPropertyDefinition($element['#field_name']);
if ($definition && empty($definition['computed'])) { if ($definition && empty($definition['computed'])) {
$variables['attributes']['data-edit-id'] = $entity->entityType() . '/' . $entity->id() . '/' . $element['#field_name'] . '/' . $element['#language'] . '/' . $element['#view_mode']; $variables['attributes']['data-edit-field-id'] = $entity->entityType() . '/' . $entity->id() . '/' . $element['#field_name'] . '/' . $element['#language'] . '/' . $element['#view_mode'];
} }
} }
...@@ -190,7 +190,7 @@ function edit_preprocess_field(&$variables) { ...@@ -190,7 +190,7 @@ function edit_preprocess_field(&$variables) {
* Implements hook_entity_view_alter(). * Implements hook_entity_view_alter().
*/ */
function edit_entity_view_alter(&$build, EntityInterface $entity, EntityDisplay $display) { function edit_entity_view_alter(&$build, EntityInterface $entity, EntityDisplay $display) {
$build['#attributes']['data-edit-entity'] = $entity->entityType() . '/' . $entity->id(); $build['#attributes']['data-edit-entity-id'] = $entity->entityType() . '/' . $entity->id();
} }
/** /**
......
...@@ -64,7 +64,7 @@ Drupal.behaviors.edit = { ...@@ -64,7 +64,7 @@ Drupal.behaviors.edit = {
// immediately. New fields will be unable to be processed immediately, but // immediately. New fields will be unable to be processed immediately, but
// will instead be queued to have their metadata fetched, which occurs below // will instead be queued to have their metadata fetched, which occurs below
// in fetchMissingMetaData(). // in fetchMissingMetaData().
$(context).find('[data-edit-id]').once('edit').each(function (index, fieldElement) { $(context).find('[data-edit-field-id]').once('edit').each(function (index, fieldElement) {
processField(fieldElement); processField(fieldElement);
}); });
...@@ -119,9 +119,9 @@ Drupal.edit = { ...@@ -119,9 +119,9 @@ Drupal.edit = {
* processed. * processed.
*/ */
$(document).on('drupalContextualLinkAdded', function (event, data) { $(document).on('drupalContextualLinkAdded', function (event, data) {
if (data.$region.is('[data-edit-entity]')) { if (data.$region.is('[data-edit-entity-id]')) {
var contextualLink = { var contextualLink = {
entityID: data.$region.attr('data-edit-entity'), entityID: data.$region.attr('data-edit-entity-id'),
el: data.$el[0], el: data.$el[0],
region: data.$region[0] region: data.$region[0]
}; };
...@@ -169,11 +169,11 @@ function initEdit (bodyElement) { ...@@ -169,11 +169,11 @@ function initEdit (bodyElement) {
* Fetch the field's metadata; queue or initialize it (if EntityModel exists). * Fetch the field's metadata; queue or initialize it (if EntityModel exists).
* *
* @param DOM fieldElement * @param DOM fieldElement
* A Drupal Field API field's DOM element with a data-edit-id attribute. * A Drupal Field API field's DOM element with a data-edit-field-id attribute.
*/ */
function processField (fieldElement) { function processField (fieldElement) {
var metadata = Drupal.edit.metadata; var metadata = Drupal.edit.metadata;
var fieldID = fieldElement.getAttribute('data-edit-id'); var fieldID = fieldElement.getAttribute('data-edit-field-id');
var entityID = extractEntityID(fieldID); var entityID = extractEntityID(fieldID);
// Early-return if metadata for this field is missing. // Early-return if metadata for this field is missing.
...@@ -428,7 +428,7 @@ function initializeEntityContextualLink (contextualLink) { ...@@ -428,7 +428,7 @@ function initializeEntityContextualLink (contextualLink) {
* The context within which to delete. * The context within which to delete.
*/ */
function deleteContainedModelsAndQueues($context) { function deleteContainedModelsAndQueues($context) {
$context.find('[data-edit-entity]').addBack('[data-edit-entity]').each(function (index, entityElement) { $context.find('[data-edit-entity-id]').addBack('[data-edit-entity-id]').each(function (index, entityElement) {
// Delete entity model. // Delete entity model.
// @todo change to findWhere() as soon as we have Backbone 1.0 in Drupal // @todo change to findWhere() as soon as we have Backbone 1.0 in Drupal
// core. @see https://drupal.org/node/1800022 // core. @see https://drupal.org/node/1800022
...@@ -450,7 +450,7 @@ function deleteContainedModelsAndQueues($context) { ...@@ -450,7 +450,7 @@ function deleteContainedModelsAndQueues($context) {
contextualLinksQueue = _.filter(contextualLinksQueue, hasOtherRegion); contextualLinksQueue = _.filter(contextualLinksQueue, hasOtherRegion);
}); });
$context.find('[data-edit-id]').addBack('[data-edit-id]').each(function (index, fieldElement) { $context.find('[data-edit-field-id]').addBack('[data-edit-field-id]').each(function (index, fieldElement) {
// Delete field models. // Delete field models.
Drupal.edit.collections.fields.chain() Drupal.edit.collections.fields.chain()
.filter(function (fieldModel) { return fieldModel.get('el') === fieldElement; }) .filter(function (fieldModel) { return fieldModel.get('el') === fieldElement; })
......
...@@ -38,8 +38,8 @@ Drupal.edit.FieldModel = Backbone.Model.extend({ ...@@ -38,8 +38,8 @@ Drupal.edit.FieldModel = Backbone.Model.extend({
// purposes: so that EditorDecorationView.renderChanged() can react to it. // purposes: so that EditorDecorationView.renderChanged() can react to it.
inTempStore: false, inTempStore: false,
// The full HTML representation of this field (with the element that has // The full HTML representation of this field (with the element that has
// the data-edit-id as the outer element). Used to propagate changes from // the data-edit-field-id as the outer element). Used to propagate changes
// this field instance to other instances of the same field. // from this field instance to other instances of the same field.
html: null html: null
}, },
......
...@@ -52,7 +52,7 @@ Drupal.edit.EditorView = Backbone.View.extend({ ...@@ -52,7 +52,7 @@ Drupal.edit.EditorView = Backbone.View.extend({
* *
* For some single cardinality fields, it may be necessary or useful to * For some single cardinality fields, it may be necessary or useful to
* not in-place edit (and hence decorate) the DOM element with the * not in-place edit (and hence decorate) the DOM element with the
* data-edit-id attribute (which is the field's wrapper), but a specific * data-edit-field-id attribute (which is the field's wrapper), but a specific
* element within the field's wrapper. * element within the field's wrapper.
* e.g. using a WYSIWYG editor on a body field should happen on the DOM * e.g. using a WYSIWYG editor on a body field should happen on the DOM
* element containing the text itself, not on the field wrapper. * element containing the text itself, not on the field wrapper.
......
...@@ -82,8 +82,8 @@ public function testUserWithoutPermission() { ...@@ -82,8 +82,8 @@ public function testUserWithoutPermission() {
$this->assertFalse(isset($settings['ajaxPageState']['js']['core/modules/edit/js/createjs/editingWidgets/formwidget.js']), "'form' in-place editor not loaded."); $this->assertFalse(isset($settings['ajaxPageState']['js']['core/modules/edit/js/createjs/editingWidgets/formwidget.js']), "'form' in-place editor not loaded.");
// HTML annotation must always exist (to not break the render cache). // HTML annotation must always exist (to not break the render cache).
$this->assertRaw('data-edit-entity="node/1"'); $this->assertRaw('data-edit-entity-id="node/1"');
$this->assertRaw('data-edit-id="node/1/body/und/full"'); $this->assertRaw('data-edit-field-id="node/1/body/und/full"');
// Retrieving the metadata should result in an empty 403 response. // Retrieving the metadata should result in an empty 403 response.
$post = array('fields[0]' => 'node/1/body/und/full'); $post = array('fields[0]' => 'node/1/body/und/full');
...@@ -138,8 +138,8 @@ public function testUserWithPermission() { ...@@ -138,8 +138,8 @@ public function testUserWithPermission() {
$this->assertFalse(isset($settings['ajaxPageState']['js']['core/modules/edit/js/createjs/editingWidgets/formwidget.js']), "'form' in-place editor not loaded."); $this->assertFalse(isset($settings['ajaxPageState']['js']['core/modules/edit/js/createjs/editingWidgets/formwidget.js']), "'form' in-place editor not loaded.");
// HTML annotation must always exist (to not break the render cache). // HTML annotation must always exist (to not break the render cache).
$this->assertRaw('data-edit-entity="node/1"'); $this->assertRaw('data-edit-entity-id="node/1"');
$this->assertRaw('data-edit-id="node/1/body/und/full"'); $this->assertRaw('data-edit-field-id="node/1/body/und/full"');
// There should be only one revision so far. // There should be only one revision so far.
$revisions = node_revision_list(node_load(1)); $revisions = node_revision_list(node_load(1));
...@@ -299,7 +299,7 @@ public function testPseudoFields() { ...@@ -299,7 +299,7 @@ public function testPseudoFields() {
$this->drupalGet('node/1'); $this->drupalGet('node/1');
// Check that the data- attribute is not added. // Check that the data- attribute is not added.
$this->assertNoRaw('data-edit-id="node/1/edit_test_pseudo_field/und/default"'); $this->assertNoRaw('data-edit-field-id="node/1/edit_test_pseudo_field/und/default"');
} }
/** /**
......
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