public function FileWidget::massageFormValues

Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::massageFormValues().

Overrides WidgetBase::massageFormValues

File

drupal/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php, line 214
Contains \Drupal\file\Plugin\field\widget\FileWidget.

Class

FileWidget
Plugin implementation of the 'file_generic' widget.

Namespace

Drupal\file\Plugin\field\widget

Code

public function massageFormValues(array $values, array $form, array &$form_state) {

  // Since file upload widget now supports uploads of more than one file at a
  // time it always returns an array of fids. We have to translate this to a
  // single fid, as field expects single value.
  $new_values = array();
  foreach ($values as &$value) {
    foreach ($value['fids'] as $fid) {
      $new_value = $value;
      $new_value['fid'] = $fid;
      unset($new_value['fids']);
      $new_values[] = $new_value;
    }
  }
  return $new_values;
}