Commit f7f07d81 authored by alexpott's avatar alexpott

Issue #2916595 by phenaproxima, AdamPS, Wim Leers: File element discards attributes if #multiple

parent b9c85bd4
......@@ -44,7 +44,7 @@ public function getInfo() {
*/
public static function processFile(&$element, FormStateInterface $form_state, &$complete_form) {
if ($element['#multiple']) {
$element['#attributes'] = ['multiple' => 'multiple'];
$element['#attributes']['multiple'] = 'multiple';
$element['#name'] .= '[]';
}
return $element;
......
<?php
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Form constructor for testing #type 'file' elements.
*
* @internal
*/
class FormTestFileForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_file';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['file'] = [
'#type' => 'file',
'#multiple' => TRUE,
'#attributes' => [
'class' => ['cagatio'],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}
<?php
namespace Drupal\Tests\system\Kernel\Form;
use Drupal\form_test\Form\FormTestFileForm;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests for the 'file' form element.
*
* @group Form
*/
class FileElementTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['form_test'];
/**
* Tests that file elements are built and processed correctly.
*/
public function testFileElement() {
$form = $this->container->get('form_builder')
->getForm(FormTestFileForm::class);
$this->assertSame('file', $form['file']['#type']);
$this->assertTrue($form['file']['#multiple']);
$this->assertContains('cagatio', $form['file']['#attributes']['class']);
}
}
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