You are here

private function AudioFieldPluginBase::validateFileAgainstPlayer in AudioField 8

Validate that a file entity will work with this player.

Parameters

\Drupal\file\FileInterface $file: A file entity.

Return value

bool Indicates if the file is valid for this player or not.

1 call to AudioFieldPluginBase::validateFileAgainstPlayer()
AudioFieldPluginBase::validateEntityAgainstPlayer in src/AudioFieldPluginBase.php
Validate that this entity will work with this player.

File

src/AudioFieldPluginBase.php, line 268

Class

AudioFieldPluginBase
Base class for audiofield plugins. Includes global functions.

Namespace

Drupal\audiofield

Code

private function validateFileAgainstPlayer(FileInterface $file) {

  // Validate the file extension agains the list of valid extensions.
  $errors = file_validate_extensions($file, implode(' ', $this->pluginDefinition["fileTypes"]));
  if (count($errors) > 0) {
    $message_data = [
      '%filename' => $file
        ->getFilename(),
      '@player' => $this
        ->getPluginLibraryName(),
      '%extensions' => implode(', ', $this->pluginDefinition["fileTypes"]),
    ];
    $this->loggerFactory
      ->get('audiofield')
      ->error('Error playing file %filename: currently selected audio player only supports the following extensions: %extensions', $message_data);
    $this->messenger
      ->addWarning($this
      ->t('Error playing file %filename: currently selected audio player only supports the following extensions: %extensions', $message_data));
    return FALSE;
  }
  return TRUE;
}