Skip to content
Snippets Groups Projects
Commit fdf3858b authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2057973 by aspilicious, Wim Leers: Don't add Edit module's data-...

Issue #2057973 by aspilicious, Wim Leers: Don't add Edit module's data- attributes on pseudo fields (as used e.g. by Display Suite).
parent 0a90af25
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -182,7 +182,13 @@ 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'];
// Fields that are not part of the entity (i.e. dynamically injected "pseudo
// 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'];
}
}
/**
......
......@@ -291,4 +291,17 @@ function testUserWithPermission() {
}
}
/**
* Tests that Edit doesn't make pseudo fields or computed fields editable.
*/
function testPseudoFields() {
\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('data-edit-id="node/1/edit_test_pseudo_field/und/default"');
}
}
......@@ -4,3 +4,36 @@
* @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',
),
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment