function 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 205  
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.