Commit 26d5a5fc authored by alexpott's avatar alexpott

Issue #2584837 by claudiu.cristea, Berdir, joelpittet, slashrsm,...

Issue #2584837 by claudiu.cristea, Berdir, joelpittet, slashrsm, ChristianAdamski: Double translation in  template_preprocess_field_multiple_value_form()
parent 5f5c6a48
......@@ -1577,7 +1577,7 @@ function template_preprocess_field_multiple_value_form(&$variables) {
'data' => array(
'#prefix' => '<h4' . $header_attributes . '>',
'title' => array(
'#markup' => t($element['#title']),
'#markup' => $element['#title'],
),
'#suffix' => '</h4>',
),
......
......@@ -8,8 +8,10 @@
namespace Drupal\field\Tests;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormState;
use Drupal\entity_test\Entity\EntityTestBaseFieldDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -655,4 +657,40 @@ function testHiddenField() {
$this->assertEqual($entity->{$field_name}->value, $value, 'New revision has the expected value for the field with the Hidden widget');
}
/**
* Tests the form display of the label for multi-value fields.
*/
public function testLabelOnMultiValueFields() {
$user = $this->drupalCreateUser(['administer entity_test content']);
$this->drupalLogin($user);
FieldStorageConfig::create([
'entity_type' => 'entity_test_base_field_display',
'field_name' => 'foo',
'type' => 'text',
'cardinality' => FieldStorageConfig::CARDINALITY_UNLIMITED,
])->save();
FieldConfig::create([
'entity_type' => 'entity_test_base_field_display',
'bundle' => 'bar',
'field_name' => 'foo',
// Set a dangerous label to test XSS filtering.
'label' => "<script>alert('a configurable field');</script>",
])->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test_base_field_display',
'bundle' => 'bar',
'mode' => 'default',
])->setComponent('foo', ['type' => 'text_textfield'])->enable()->save();
$entity = EntityTestBaseFieldDisplay::create(['type' => 'bar']);
$entity->save();
$this->drupalGet('entity_test_base_field_display/manage/' . $entity->id());
$this->assertResponse(200);
$this->assertText('A field with multiple values');
// Test if labels were XSS filtered.
$this->assertEscaped("<script>alert('a configurable field');</script>");
}
}
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity_test\FieldStorageDefinition;
/**
* Defines a test entity class for base fields display.
......@@ -23,9 +24,10 @@
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler"
* },
* base_table = "entity_test",
* base_table = "entity_test_base_field_display",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "bundle" = "type"
* },
......@@ -70,6 +72,18 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
'weight' => 11,
));
$fields['test_display_multiple'] = BaseFieldDefinition::create('text')
->setLabel(t('A field with multiple values'))
->setCardinality(FieldStorageDefinition::CARDINALITY_UNLIMITED)
->setDisplayOptions('view', array(
'type' => 'text_default',
'weight' => 12,
))
->setDisplayOptions('form', array(
'type' => 'text_textfield',
'weight' => 12,
));
return $fields;
}
......
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