You are here

protected function MetadataEventSubscriber::createData in Filebrowser 3.x

Same name and namespace in other branches
  1. 8.2 src/EventSubscriber/MetadataEventSubscriber.php \Drupal\filebrowser\EventSubscriber\MetadataEventSubscriber::createData()
1 call to MetadataEventSubscriber::createData()
MetadataEventSubscriber::setMetadata in src/EventSubscriber/MetadataEventSubscriber.php

File

src/EventSubscriber/MetadataEventSubscriber.php, line 72

Class

MetadataEventSubscriber

Namespace

Drupal\filebrowser\EventSubscriber

Code

protected function createData($id, $fid, $file, $subdir_fid) {
  if ($file->fileData->type == 'file') {

    /** @var DisplayFile $file */
    switch ($id) {
      case 'description':
        return [
          'content' => $this
            ->generateDescription($file, $subdir_fid, $fid),
          'theme' => 'filebrowser_description',
        ];
      case 'size':
        return [
          'content' => format_size($file->fileData->size),
          'theme' => "",
        ];
      case 'created':
        return [
          'theme' => "",
          'content' => \Drupal::service('date.formatter')
            ->format($file->fileData->timestamp, 'short'),
        ];
      case 'mimetype':
        return [
          'theme' => "",
          'content' => $file->fileData->mimetype,
        ];
    }
  }
  else {
    if ($id == 'description') {
      return [
        'content' => $this
          ->generateDescription($file, $subdir_fid, $fid),
        'theme' => 'filebrowser_description',
      ];
    }
    else {
      return [
        'theme' => "",
        'content' => "",
      ];
    }
  }
}