You are here

public static function WebformAdminConfigElementsForm::validateMaxFilesize in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Form/AdminConfig/WebformAdminConfigElementsForm.php \Drupal\webform\Form\AdminConfig\WebformAdminConfigElementsForm::validateMaxFilesize()

Wrapper for FileItem::validateMaxFilesize.

File

src/Form/AdminConfig/WebformAdminConfigElementsForm.php, line 581

Class

WebformAdminConfigElementsForm
Configure webform admin settings for elements.

Namespace

Drupal\webform\Form\AdminConfig

Code

public static function validateMaxFilesize($element, FormStateInterface $form_state) {

  // Issue #2359675: File field's Maximum upload size always passes validation.
  // if (class_exists('\Drupal\file\Plugin\Field\FieldType\FileItem')) {
  //   FileItem::validateMaxFilesize($element, $form_state);
  // }
  // @see \Drupal\file\Plugin\Field\FieldType\FileItem::validateMaxFilesize
  if (!empty($element['#value']) && !Bytes::toInt($element['#value'])) {
    $form_state
      ->setError($element, t('The "@name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', [
      '@name' => $element['#title'],
    ]));
  }
}