function FileWidget::value

Same name in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::value()
  2. 8.9.x core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::value()
  3. 11.x core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::value()

Form API callback. Retrieves the value for the file_generic field element.

This method is assigned as a #value_callback in formElement() method.

File

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

Class

FileWidget
Plugin implementation of the 'file_generic' widget.

Namespace

Drupal\file\Plugin\Field\FieldWidget

Code

public static function value($element, $input, FormStateInterface $form_state) {
    if ($input) {
        if (empty($input['display'])) {
            // Updates the display field with the default value because
            // #display_field is invisible.
            if (empty($input['fids'])) {
                $input['display'] = $element['#display_default'];
            }
            else {
                $input['display'] = $element['#display_field'] ? 0 : 1;
            }
        }
    }
    // We depend on the managed file element to handle uploads.
    $return = ManagedFile::valueCallback($element, $input, $form_state);
    // Ensure that all the required properties are returned even if empty.
    $return += [
        'fids' => [],
        'display' => 1,
        'description' => '',
    ];
    return $return;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.