function File::valueCallback
Overrides FormElementBase::valueCallback
File
-
core/
lib/ Drupal/ Core/ Render/ Element/ File.php, line 85
Class
- File
- Provides a form element for uploading a file.
Namespace
Drupal\Core\Render\ElementCode
public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
if ($input === FALSE) {
return NULL;
}
$parents = $element['#parents'];
$element_name = array_shift($parents);
$uploaded_files = \Drupal::request()->files
->get('files', []);
$uploaded_file = $uploaded_files[$element_name] ?? NULL;
if ($uploaded_file) {
// Cast this to an array so that the structure is consistent regardless of
// whether #value is set or not.
return (array) $uploaded_file;
}
return NULL;
}