Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FileWidget.php

function FileWidget::massageFormValues

Overrides WidgetBase::massageFormValues

File

core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php, line 280

Class

FileWidget
Plugin implementation of the 'file_generic' widget.

Namespace

Drupal\file\Plugin\Field\FieldWidget

Code

public function massageFormValues(array $values, array $form, FormStateInterface $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 = [];
    foreach ($values as &$value) {
        foreach ($value['fids'] as $fid) {
            $new_value = $value;
            $new_value['target_id'] = $fid;
            unset($new_value['fids']);
            $new_values[] = $new_value;
        }
    }
    return $new_values;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal