You are here

class UserActionsEventSubscriber in Filebrowser 8.2

Same name and namespace in other branches
  1. 3.x src/EventSubscriber/UserActionsEventSubscriber.php \Drupal\filebrowser\EventSubscriber\UserActionsEventSubscriber

Class UserActionsEventSubscriber.

@package Drupal\filebrowser

Hierarchy

Expanded class hierarchy of UserActionsEventSubscriber

1 string reference to 'UserActionsEventSubscriber'
filebrowser.services.yml in ./filebrowser.services.yml
filebrowser.services.yml
1 service uses UserActionsEventSubscriber
filebrowser.user_actions in ./filebrowser.services.yml
Drupal\filebrowser\EventSubscriber\UserActionsEventSubscriber

File

src/EventSubscriber/UserActionsEventSubscriber.php, line 15

Namespace

Drupal\filebrowser\EventSubscriber
View source
class UserActionsEventSubscriber implements EventSubscriberInterface {
  use StringTranslationTrait;
  public function __construct() {
  }

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    $events['filebrowser.user_actions'][] = [
      'handler',
      0,
    ];
    return $events;
  }
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UserActionsEventSubscriber::getSubscribedEvents static function Returns an array of event names this subscriber wants to listen to.
UserActionsEventSubscriber::handler public function
UserActionsEventSubscriber::__construct public function