public function FileUploadForm::validateUploadElement in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::validateUploadElement()
Validates the upload element.
Parameters
array $element: The upload element.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array The processed upload element.
File
- core/
modules/ media_library/ src/ Form/ FileUploadForm.php, line 188
Class
- FileUploadForm
- Creates a form to create media entities from uploaded files.
Namespace
Drupal\media_library\FormCode
public function validateUploadElement(array $element, FormStateInterface $form_state) {
if ($form_state::hasAnyErrors()) {
// When an error occurs during uploading files, remove all files so the
// user can re-upload the files.
$element['#value'] = [];
}
$values = $form_state
->getValue('upload', []);
if (count($values['fids']) > $element['#cardinality'] && $element['#cardinality'] !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$form_state
->setError($element, $this
->t('A maximum of @count files can be uploaded.', [
'@count' => $element['#cardinality'],
]));
$form_state
->setValue('upload', []);
$element['#value'] = [];
}
return $element;
}