You are here

private function AudioFieldPluginBase::getFiletype in AudioField 8

Get the filetype for an item.

Parameters

\Drupal\file\Plugin\Field\FieldType\FileItem|\Drupal\link\Plugin\Field\FieldType\LinkItem $item: Item for which we are determining filetype.

Return value

string Filetype for the item.

1 call to AudioFieldPluginBase::getFiletype()
AudioFieldPluginBase::getAudioRenderInfo in src/AudioFieldPluginBase.php
Get required rendering information from an entity.

File

src/AudioFieldPluginBase.php, line 434

Class

AudioFieldPluginBase
Base class for audiofield plugins. Includes global functions.

Namespace

Drupal\audiofield

Code

private function getFiletype($item) {

  // Handle File entity.
  if ($this
    ->getClassType($item) == 'FileItem') {

    // Load the associated file.
    $file = $this
      ->loadFileFromItem($item);
    return pathinfo($file
      ->getFilename(), PATHINFO_EXTENSION);
  }
  elseif ($this
    ->getClassType($item) == 'LinkItem') {
    return pathinfo($this
      ->getAudioSource($item)
      ->toString(), PATHINFO_EXTENSION);
  }
  return '';
}