AudioStream.php in Media entity audio 8.3
File
src/Plugin/media/Source/AudioStream.php
View source
<?php
namespace Drupal\media_entity_audio\Plugin\media\Source;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\media\MediaSourceBase;
use Drupal\media\MediaTypeInterface;
use Drupal\media\MediaInterface;
class AudioStream extends MediaSourceBase {
public function getMetadata(MediaInterface $media, $attribute_name) {
switch ($attribute_name) {
case 'default_name':
return basename($media
->get($this->configuration['source_field'])->uri);
}
return parent::getMetadata($media, $attribute_name);
}
public function getMetadataAttributes() {
return [
'default_name' => $this
->t('Name'),
];
}
public function createSourceField(MediaTypeInterface $type) {
return parent::createSourceField($type);
}
public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
$display
->setComponent($this
->getSourceFieldDefinition($type)
->getName(), [
'type' => 'audio_stream_html5',
'label' => 'visually_hidden',
]);
}
}