You are here

protected function ServerFileList::createServerFileList in Filebrowser 8.2

Same name and namespace in other branches
  1. 3.x src/ServerFileList.php \Drupal\filebrowser\ServerFileList::createServerFileList()

Retrieves files from the file system

Parameters

NodeInterface $node:

string $relative_path:

Return value

array list of files filtered as per node settings and restrictions returns an array of objects keyed to the uri: [public://directory/ic_autorenew_white_18px.svg] => stdClass Object( [uri] => public://directory/ic_autorenew_white_18px.svg // file_scan_directory [filename] => ic_autorenew_white_18px.svg // file_scan_directory [name] => ic_autorenew_white_18px // file_scan_directory [url] => http://drupal8.dev/sites/default/files/NFTR/file.svg [mimetype] => application/octet-stream [size] => 394 [type] => file [timestamp] => 1460968364)

1 call to ServerFileList::createServerFileList()
ServerFileList::__construct in src/ServerFileList.php
ServerFileList constructor.

File

src/ServerFileList.php, line 66

Class

ServerFileList

Namespace

Drupal\filebrowser

Code

protected function createServerFileList($node, $relative_path) {

  /** @var Filebrowser $folder_path */
  $folder_path = $node->filebrowser->folderPath;
  $directory = $folder_path . $relative_path;
  $files = \Drupal::service('file_system')
    ->scanDirectory($directory, '/.*/', [
    'recurse' => false,
  ]);
  $validator = \Drupal::service('filebrowser.validator');
  $guessor = \Drupal::service('file.mime_type.guesser');
  foreach ($files as $key => $file) {
    $file->url = file_create_url($file->uri);

    // Complete the required file data
    $file->mimetype = $guessor
      ->guess($file->filename);
    $file->size = filesize($file->uri);
    $file->type = filetype($file->uri);
    $file->timestamp = filectime($file->uri);
    if ($file->type != 'dir' && !$validator
      ->whiteListed($file->filename, $node->filebrowser->whitelist) || $validator
      ->blackListed($file->filename, $node->filebrowser->forbiddenFiles) || !$node->filebrowser->exploreSubdirs && $file->type == 'dir') {
      unset($files[$key]);
    }
  }
  return $files;
}