diff --git a/core/modules/edit/edit.module b/core/modules/edit/edit.module index 000f67f..aefe7ec 100644 --- a/core/modules/edit/edit.module +++ b/core/modules/edit/edit.module @@ -166,7 +166,11 @@ function edit_field_formatter_info_alter(&$info) { function edit_preprocess_field(&$variables) { $element = $variables['element']; $entity = $element['#object']; - $variables['attributes']['data-edit-id'] = $entity->entityType() . '/' . $entity->id() . '/' . $element['#field_name'] . '/' . $element['#language'] . '/' . $element['#view_mode']; + + $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']; + } } /** diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php index eecf864..90a0fe2 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php @@ -291,4 +291,17 @@ function testUserWithPermission() { } } + /** + * Tests that Edit doesn't set a data- attribute on pseudo fields or computed fields. + */ + function tesPseudoFields() { + \Drupal::moduleHandler()->install(array('edit_test')); + + $this->drupalLogin($this->author_user); + $this->drupalGet('node/1'); + + // Check that the data- attribute is not added. + $this->assertNoRaw('node/1/edit_test_pseudo_field/und/default'); + } + } diff --git a/core/modules/edit/tests/modules/edit_test.module b/core/modules/edit/tests/modules/edit_test.module index d74528d..559ad55 100644 --- a/core/modules/edit/tests/modules/edit_test.module +++ b/core/modules/edit/tests/modules/edit_test.module @@ -4,3 +4,38 @@ * @file * Helper module for the Edit tests. */ + +use Drupal\Core\Language\Language; +use Drupal\Core\Entity\EntityInterface; +use Drupal\entity\Entity\EntityDisplay; + +/** + * Implements hook_entity_view_alter(). + */ +function edit_test_entity_view_alter(&$build, EntityInterface $entity, EntityDisplay $display) { + + if ($entity->entityType() == 'node' && $entity->bundle() == 'article') { + $build['pseudo'] = array( + '#theme' => 'field', + '#title' => 'My pseudo field', + '#field_name' => 'edit_test_pseudo_field', + '#label_display' => 'Label', + '#entity_type' => $entity->entityType(), + '#bundle' => $entity->bundle(), + '#language' => Language::LANGCODE_NOT_SPECIFIED, + '#field_type' => 'pseudo', + '#view_mode' => 'default', + '#object' => $entity, + '#access' => TRUE, + '#items' => array( + 0 => array( + 'value' => 'pseudo field', + ), + ), + 0 => array( + '#markup' => 'pseudo field', + ), + ); + } + +}