You are here

public static function FileItem::validateMaxFilesize in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::validateMaxFilesize()
  2. 10 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::validateMaxFilesize()

Form API callback.

Ensures that a size has been entered and that it can be parsed by \Drupal\Component\Utility\Bytes::toInt().

This function is assigned as an #element_validate callback in fieldSettingsForm().

File

core/modules/file/src/Plugin/Field/FieldType/FileItem.php, line 248

Class

FileItem
Plugin implementation of the 'file' field type.

Namespace

Drupal\file\Plugin\Field\FieldType

Code

public static function validateMaxFilesize($element, FormStateInterface $form_state) {
  if (!empty($element['#value']) && !is_numeric(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'],
    ]));
  }
}