Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / media / src / Plugin / media / Source / File.php
index b6ad9799e8e84b4f8da328ab02b43e105f99d222..0f7631ec2771516af230a81591608e766a66dd5a 100644 (file)
@@ -22,11 +22,29 @@ use Drupal\media\MediaSourceBase;
  */
 class File extends MediaSourceBase {
 
+  /**
+   * Key for "MIME type" metadata attribute.
+   *
+   * @var string
+   */
+  const METADATA_ATTRIBUTE_MIME = 'mimetype';
+
+  /**
+   * Key for "File size" metadata attribute.
+   *
+   * @var string
+   */
+  const METADATA_ATTRIBUTE_SIZE = 'filesize';
+
+
   /**
    * {@inheritdoc}
    */
   public function getMetadataAttributes() {
-    return [];
+    return [
+      static::METADATA_ATTRIBUTE_MIME => $this->t('MIME type'),
+      static::METADATA_ATTRIBUTE_SIZE => $this->t('File size'),
+    ];
   }
 
   /**
@@ -40,6 +58,12 @@ class File extends MediaSourceBase {
       return parent::getMetadata($media, $attribute_name);
     }
     switch ($attribute_name) {
+      case 'mimetype':
+        return $file->getMimeType();
+
+      case 'filesize':
+        return $file->getSize();
+
       case 'default_name':
         return $file->getFilename();