AudioFile.php

Same filename in other branches
  1. 8.9.x core/modules/media/src/Plugin/media/Source/AudioFile.php
  2. 10 core/modules/media/src/Plugin/media/Source/AudioFile.php
  3. 11.x core/modules/media/src/Plugin/media/Source/AudioFile.php

Namespace

Drupal\media\Plugin\media\Source

File

core/modules/media/src/Plugin/media/Source/AudioFile.php

View source
<?php

namespace Drupal\media\Plugin\media\Source;

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\media\MediaTypeInterface;

/**
 * Media source wrapping around an audio file.
 *
 * @see \Drupal\file\FileInterface
 *
 * @MediaSource(
 *   id = "audio_file",
 *   label = @Translation("Audio file"),
 *   description = @Translation("Use audio files for reusable media."),
 *   allowed_field_types = {"file"},
 *   default_thumbnail_filename = "audio.png"
 * )
 */
class AudioFile extends File {
    
    /**
     * {@inheritdoc}
     */
    public function createSourceField(MediaTypeInterface $type) {
        return parent::createSourceField($type)->set('settings', [
            'file_extensions' => 'mp3 wav aac',
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
        $display->setComponent($this->getSourceFieldDefinition($type)
            ->getName(), [
            'type' => 'file_audio',
            'label' => 'visually_hidden',
        ]);
    }

}

Classes

Title Deprecated Summary
AudioFile Media source wrapping around an audio file.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.