You are here

public function UserActionsEventSubscriber::handler in Filebrowser 3.x

Same name and namespace in other branches
  1. 8.2 src/EventSubscriber/UserActionsEventSubscriber.php \Drupal\filebrowser\EventSubscriber\UserActionsEventSubscriber::handler()

File

src/EventSubscriber/UserActionsEventSubscriber.php, line 30

Class

UserActionsEventSubscriber
Class UserActionsEventSubscriber.

Namespace

Drupal\filebrowser\EventSubscriber

Code

public function handler(UserActionsEvent $event) {
  $actions = [];
  $fileData = $event
    ->getFileData();
  $node = \Drupal::request()->attributes
    ->get('node');
  if ($fileData['data']['stats']['files_count'] || $fileData['data']['stats']['folders_count']) {
    if (\Drupal::service('filebrowser.common')
      ->canDownloadArchive($node) && function_exists('zip_open')) {
      $actions[] = [
        'operation' => 'download',
        'title' => $this
          ->t("Download selected items as an ZIP archive (only files)"),
      ];
    }
    if (\Drupal::currentUser()
      ->hasPermission(Common::DELETE_FILES)) {
      $actions[] = [
        'operation' => 'delete',
        'title' => $this
          ->t("Delete selected items"),
      ];
    }
    if (\Drupal::currentUser()
      ->hasPermission(Common::RENAME_FILES)) {
      $actions[] = [
        'operation' => 'rename',
        'title' => $this
          ->t("Rename selected items"),
      ];
    }
  }
  $event
    ->setActions($actions);
}