Overrides \Drupal\file\Plugin\field\widget\FileWidget::formMultipleElements().
Special handling for draggable multiple widgets and 'add more' button.
Overrides FileWidget::formMultipleElements
protected function formMultipleElements(EntityInterface $entity, array $items, $langcode, array &$form, array &$form_state) {
$elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state);
if ($this->field['cardinality'] == 1) {
// If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fids'])) {
$elements[0]['#description'] = theme('file_upload_help', array(
'description' => $this->instance['description'],
'upload_validators' => $elements[0]['#upload_validators'],
'cardinality' => $this->field['cardinality'],
));
}
}
else {
$elements['#file_upload_description'] = theme('file_upload_help', array(
'upload_validators' => $elements[0]['#upload_validators'],
'cardinality' => $this->field['cardinality'],
));
}
return $elements;
}