You are here

private function AudioFieldPluginBase::validateLinkAgainstPlayer in AudioField 8

Validate that a link entity will work with this player.

Parameters

\Drupal\Core\Url $link: Url to the link.

Return value

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

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

File

src/AudioFieldPluginBase.php, line 293

Class

AudioFieldPluginBase
Base class for audiofield plugins. Includes global functions.

Namespace

Drupal\audiofield

Code

private function validateLinkAgainstPlayer(Url $link) {

  // Check for a valid link and a valid extension.
  $extension = pathinfo($link
    ->toString(), PATHINFO_EXTENSION);
  if (!UrlHelper::isValid($link
    ->toString(), FALSE) || empty($extension)) {

    // We are currently not validating file types for links.
    $message_data = [
      '%link' => $link
        ->toString(),
    ];
    $this->loggerFactory
      ->get('audiofield')
      ->error('Error playing file: invalid link: %link', $message_data);
    $this->messenger
      ->addWarning($this
      ->t('Error playing file: invalid link: %link', $message_data));
    return FALSE;
  }
  return TRUE;
}