Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / media / src / Plugin / media / Source / AudioFile.php
diff --git a/web/core/modules/media/src/Plugin/media/Source/AudioFile.php b/web/core/modules/media/src/Plugin/media/Source/AudioFile.php
new file mode 100644 (file)
index 0000000..2229143
--- /dev/null
@@ -0,0 +1,39 @@
+<?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',
+    ]);
+  }
+
+}