public static function validate(array &$element, FormStateInterface $form_state) {
    if ($element['#value']) {
      $file = File::load($element['#value']);

      $errors = file_validate($file, $element['#upload_validators']);
      if ($errors) {
        foreach ($errors as $error) {
          $form_state->setError($element, (string) $error);
        }
        static::delete($element);
      }
    }
  }
public static function validate(array &$element, FormStateInterface $form_state) {
    if ($element['#value']) {
      $file = File::load($element['#value']);

      $errors = file_validate($file, $element['#upload_validators']);
      if ($errors) {
        foreach ($errors as $error) {
          $form_state->setError($element, (string) $error);
        }
        static::delete($element);
      }
    }
  }
public static function validate ( array & $ element , FormStateInterface $ form_state ) { if ( $ element [ '#value' ] ) { $ file = File :: load ( $ element [ '#value' ] ) ; $ errors = file_validate ( $ file , $ element [ '#upload_validators' ] ) ; if ( $ errors ) { foreach ( $ errors as $ error ) { $ form_state -> setError ( $ element , ( string ) $ error ) ; } static :: delete ( $ element ) ; } } }
Validates the uploaded file.

@param array $element
The element.
@param \Drupal\Core\Form\FormStateInterface $form_state
The current form state.
Validates the uploaded file .