You are here

public static function BlockUploadBuild::blockUploadGetValidators in Block Upload 8

Returns validators array.

Return value

array List of validators.

2 calls to BlockUploadBuild::blockUploadGetValidators()
BlockUploadForm::buildForm in src/Form/BlockUploadForm.php
Form constructor.
BlockUploadPluploadForm::buildForm in src/Form/BlockUploadPluploadForm.php
Form constructor.

File

src/BlockUploadBuild.php, line 115

Class

BlockUploadBuild
BlockUploadBuild class.

Namespace

Drupal\block_upload

Code

public static function blockUploadGetValidators($field_name, $fields_info, $node) {
  $settings = $node
    ->get($field_name)
    ->getSettings();
  $validators = [
    'file_validate_extensions' => [
      $settings['file_extensions'],
    ],
    'file_validate_size' => [
      Bytes::toInt($settings['max_filesize']),
    ],
  ];
  $min_resolution = isset($settings['min_resolution']) ? $settings['min_resolution'] : NULL;
  $max_resolution = isset($settings['max_resolution']) ? $settings['max_resolution'] : NULL;
  if (isset($min_resolution) || isset($min_resolution)) {
    $validators['file_validate_image_resolution'] = [
      $max_resolution,
      $min_resolution,
    ];
    $validators['file_validate_image_min_resolution'] = [
      $min_resolution,
    ];
  }
  return $validators;
}