You are here

protected function DisplayFileList::createFileDisplayList in Filebrowser 8.2

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

Creates the data required to build the Filebrowser listing in following steps

  • look at the request object and decide what files are requested
  • Retrieves the DB records for this Filebrowser
  • Get all the files from the server and filter them for *per-node* settings
  • Iterate over this file list and build the DB contents for storage
  • The DB contents should reflect the filtered file list from the server
  • The purpose of the DB contents is to provide an url over which files and folders can be requested/
  • return the list of files (DB contents) for display in the node.

Display depends on the selected view. example: list view returns a table displaying one file per row.

Return value

mixed

1 call to DisplayFileList::createFileDisplayList()
DisplayFileList::__construct in src/File/DisplayFileList.php

File

src/File/DisplayFileList.php, line 136

Class

DisplayFileList
Class FileDisplayList @package Drupal\filebrowser This class holds the list of files to be displayed on the filebrowser node. These files are retrieved from the filesystem and filtered for user and node access. The array produced by this class…

Namespace

Drupal\filebrowser\File

Code

protected function createFileDisplayList() {

  // file list
  $cid = 'filebrowser/' . $this->node
    ->id() . '/' . $this->fid;

  //you are requesting a subdir: node/23?fid=nn
  if ($this->fid) {
    $content = $this->storage
      ->nodeContentLoadMultiple([
      $this->fid,
    ]);

    //debug($content[$this->fid]);
    if (empty($content[$this->fid])) {

      // There is no DB data for this fid
      return false;
    }

    // When accessing a subdir relativePath will be /subdir[/other sub dir]
    $this->relativePath = $content[$this->fid]['path'];
    $this->fsRoot = $this->relativePath;
  }
  else {
    $this->relativePath = '/';
  }
  $this->isSubDir = $this->relativePath != '/';

  // If this is a sub dir, check if we may access it, else redirect to root_dir.
  if ($this->isSubDir && !$this->common
    ->canExploreSubFolders($this->node)) {
    \Drupal::messenger()
      ->addError($this
      ->t('You\'re not allowed to browse sub folders.'));
    return false;
  }

  // full path valid?
  if ($this->fsRoot === false) {
    \Drupal::messenger()
      ->addError($this
      ->t('Configured folder is not readable or is not a directory.'));
    return false;
  }

  // retrieve files from the system - returned list is filtered *per-node* settings
  $list = new ServerFileList($this->node, $this->relativePath);
  $this->serverFileList = $list
    ->getList();

  //debug($this->serverFileList);

  // create DB contents and return the files for display ($result)
  $result = $this
    ->processServerFileList();
  $this->files = $result;
  $this->data['fid'] = $this->fid;

  // cache the results
  $cache = [
    'files' => $this->files,
    'data' => $this->data,
  ];
  \Drupal::cache()
    ->set($cid, $cache, -1, [
    'filebrowser:node:' . $this->node
      ->id(),
  ]);
  return $this;
}