You are here

public function Core::opBrowse in IMCE 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/ImcePlugin/Core.php \Drupal\imce\Plugin\ImcePlugin\Core::opBrowse()

Operation handler: browse.

File

src/Plugin/ImcePlugin/Core.php, line 36

Class

Core
Defines Imce Core plugin.

Namespace

Drupal\imce\Plugin\ImcePlugin

Code

public function opBrowse(ImceFM $fm) {
  if ($folder = $fm->activeFolder) {
    $folder
      ->scan();
    $uri = $folder
      ->getUri();
    $uri_prefix = substr($uri, -1) === '/' ? $uri : $uri . '/';
    $content = [
      'props' => $fm
        ->getFolderProperties($uri),
    ];
    if ($folder
      ->getPermission('browse_files')) {
      foreach ($folder->files as $name => $file) {
        $content['files'][$name] = $fm
          ->getFileProperties($uri_prefix . $name);
      }
    }
    if ($folder
      ->getPermission('browse_subfolders')) {
      foreach ($folder->subfolders as $name => $subfolder) {
        $content['subfolders'][$name] = $fm
          ->getFolderProperties($uri_prefix . $name);
      }
    }
    $fm
      ->addResponse('content', $content);
  }
}