function FileWidget::value
Same name in other branches
- 8.9.x core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::value()
- 10 core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php \Drupal\file\Plugin\Field\FieldWidget\FileWidget::value()
- 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 319
Class
- FileWidget
- Plugin implementation of the 'file_generic' widget.
Namespace
Drupal\file\Plugin\Field\FieldWidgetCode
public static function value($element, $input, FormStateInterface $form_state) {
if ($input) {
// Checkboxes lose their value when empty.
// If the display field is present make sure its unchecked value is saved.
if (empty($input['display'])) {
$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.