You are here

protected function DropzoneJsEbWidget::validateExtension in DropzoneJS 8.2

Same name and namespace in other branches
  1. 8 modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php \Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget\DropzoneJsEbWidget::validateExtension()

Validate extension.

Because while validating we don't have a file object yet, we can't use file_validate_extensions directly. That's why we make a copy of that function here and switch the file argument with filename argument.

Parameters

string $filename: The filename we want to test.

string $extensions: A space separated list of extensions.

Return value

bool True if the file's extension is a valid one. False otherwise.

File

modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php, line 366

Class

DropzoneJsEbWidget
Provides an Entity Browser widget that uploads new files.

Namespace

Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget

Code

protected function validateExtension($filename, $extensions) {
  $regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
  if (!preg_match($regex, $filename)) {
    return FALSE;
  }
  return TRUE;
}