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) {
* following in-place editing in the exact way it was displayed originally),
* implement this hook.
*
* Edit module integrates with HTML elements with data-edit-id attributes. For
* example: data-edit-id="node/1/<field-name>/und/<module-name>-<custom-id>".
* Edit module integrates with HTML elements with data-edit-field-id attributes.
* 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
* 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
* the original display.
*
......
......@@ -182,7 +182,7 @@ function edit_preprocess_field(&$variables) {
// fields") and computed fields are not editable.
$definition = $entity->getPropertyDefinition($element['#field_name']);
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) {
* Implements hook_entity_view_alter().
*/
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 = {
// immediately. New fields will be unable to be processed immediately, but
// will instead be queued to have their metadata fetched, which occurs below
// 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);
});
......@@ -119,9 +119,9 @@ Drupal.edit = {
* processed.
*/
$(document).on('drupalContextualLinkAdded', function (event, data) {
if (data.$region.is('[data-edit-entity]')) {
if (data.$region.is('[data-edit-entity-id]')) {
var contextualLink = {
entityID: data.$region.attr('data-edit-entity'),
entityID: data.$region.attr('data-edit-entity-id'),
el: data.$el[0],
region: data.$region[0]
};
......@@ -169,11 +169,11 @@ function initEdit (bodyElement) {
* Fetch the field's metadata; queue or initialize it (if EntityModel exists).
*
* @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) {
var metadata = Drupal.edit.metadata;
var fieldID = fieldElement.getAttribute('data-edit-id');
var fieldID = fieldElement.getAttribute('data-edit-field-id');
var entityID = extractEntityID(fieldID);
// Early-return if metadata for this field is missing.
......@@ -428,7 +428,7 @@ function initializeEntityContextualLink (contextualLink) {
* The context within which to delete.
*/
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.
// @todo change to findWhere() as soon as we have Backbone 1.0 in Drupal
// core. @see https://drupal.org/node/1800022
......@@ -450,7 +450,7 @@ function deleteContainedModelsAndQueues($context) {
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.
Drupal.edit.collections.fields.chain()
.filter(function (fieldModel) { return fieldModel.get('el') === fieldElement; })
......
......@@ -38,8 +38,8 @@ Drupal.edit.FieldModel = Backbone.Model.extend({
// purposes: so that EditorDecorationView.renderChanged() can react to it.
inTempStore: false,
// 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
// this field instance to other instances of the same field.
// the data-edit-field-id as the outer element). Used to propagate changes
// from this field instance to other instances of the same field.
html: null
},
......
......@@ -52,7 +52,7 @@ Drupal.edit.EditorView = Backbone.View.extend({
*
* For some single cardinality fields, it may be necessary or useful to
* 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.
* 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.
......
......@@ -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.");
// HTML annotation must always exist (to not break the render cache).
$this->assertRaw('data-edit-entity="node/1"');
$this->assertRaw('data-edit-id="node/1/body/und/full"');
$this->assertRaw('data-edit-entity-id="node/1"');
$this->assertRaw('data-edit-field-id="node/1/body/und/full"');
// Retrieving the metadata should result in an empty 403 response.
$post = array('fields[0]' => 'node/1/body/und/full');
......@@ -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.");
// HTML annotation must always exist (to not break the render cache).
$this->assertRaw('data-edit-entity="node/1"');
$this->assertRaw('data-edit-id="node/1/body/und/full"');
$this->assertRaw('data-edit-entity-id="node/1"');
$this->assertRaw('data-edit-field-id="node/1/body/und/full"');
// There should be only one revision so far.
$revisions = node_revision_list(node_load(1));
......@@ -299,7 +299,7 @@ public function testPseudoFields() {
$this->drupalGet('node/1');
// 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