Issue #3004738 by NickWilde: Multiple Value Field Doesn't Render Attributes

8.7.x
Lee Rowlands 2018-10-26 19:25:46 +10:00
parent a92a3693ee
commit 18c57b6f71
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
5 changed files with 37 additions and 6 deletions

View File

@ -1606,6 +1606,7 @@ function template_preprocess_field(&$variables, $hook) {
function template_preprocess_field_multiple_value_form(&$variables) {
$element = $variables['element'];
$variables['multiple'] = $element['#cardinality_multiple'];
$variables['attributes'] = $element['#attributes'];
if ($variables['multiple']) {
$table_id = Html::getUniqueId($element['#field_name'] . '_values');

View File

@ -403,11 +403,12 @@ class FormTest extends FieldTestBase {
$this->field['field_name'] = $field_name;
FieldStorageConfig::create($field_storage)->save();
FieldConfig::create($this->field)->save();
entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
$form = entity_get_form_display($this->field['entity_type'], $this->field['bundle'], 'default')
->setComponent($field_name, [
'type' => 'test_field_widget_multiple',
])
->save();
]);
$form->save();
$session = $this->assertSession();
// Display creation form.
$this->drupalGet('entity_test/add');
@ -435,6 +436,16 @@ class FormTest extends FieldTestBase {
$this->assertRaw('this field cannot hold more than 4 values', 'Form validation failed.');
// Check that the field values were not submitted.
$this->assertFieldValues($entity_init, $field_name, [1, 2, 3]);
// Check that Attributes are rendered on the multivalue container if it is
// a multiple widget form.
$form->setComponent($field_name, [
'type' => 'entity_reference_autocomplete',
])
->save();
$this->drupalGet('entity_test/manage/' . $id . '/edit');
$name = str_replace('_', '-', $field_name);
$session->responseContains('data-drupal-selector="edit-' . $name . '"');
}
/**

View File

@ -22,7 +22,13 @@
*/
#}
{% if multiple %}
<div class="js-form-item form-item">
{%
set classes = [
'js-form-item',
'form-item'
]
%}
<div{{ attributes.addClass(classes) }}>
{{ table }}
{% if description.content %}
<div{{ description.attributes.addClass('description') }} >{{ description.content }}</div>

View File

@ -20,7 +20,13 @@
*/
#}
{% if multiple %}
<div class="js-form-item form-item">
{%
set classes = [
'js-form-item',
'form-item'
]
%}
<div{{ attributes.addClass(classes) }}>
{{ table }}
{% if description.content %}
<div{{ description.attributes.addClass('description') }} >{{ description.content }}</div>

View File

@ -19,8 +19,15 @@
* @see template_preprocess_field_multiple_value_form()
*/
#}
{% if multiple %}
<div class="js-form-item form-item">
{%
set classes = [
'js-form-item',
'form-item'
]
%}
<div{{ attributes.addClass(classes) }}>
{{ table }}
{% if description.content %}
<div{{ description.attributes.addClass('description') }} >{{ description.content }}</div>