foldershare-8.x-1.2/src/Plugin/FolderShareCommand/Download.php
src/Plugin/FolderShareCommand/Download.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | <?php namespace Drupal\foldershare\Plugin\FolderShareCommand; use Drupal\Core\Url; use Drupal\foldershare\Constants; /** * Defines a command plugin to download files or folders. * * The command downloads a single selected entity. * * Configuration parameters: * - 'parentId': the parent folder, if any. * - 'selectionIds': selected entities to download. * * @ingroup foldershare * * @FolderShareCommand( * id = "foldersharecommand_download", * label = @Translation("Download"), * menuNameDefault = @Translation("Download"), * menuName = @Translation("Download"), * description = @Translation("Download selected files and folders. Folders and lists of files are automatically downloaded as a newly-created ZIP archive."), * category = "import & export", * weight = 20, * parentConstraints = { * "kinds" = { * "rootlist", * "any", * }, * "access" = "view", * }, * selectionConstraints = { * "types" = { * "parent", * "one", * "many", * }, * "kinds" = { * "file", * "image", * "folder", * }, * "access" = "view", * }, * ) */ class Download extends FolderShareCommandBase { /*--------------------------------------------------------------------- * * Execute behavior. * *---------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function getExecuteBehavior() { // Prior to (and thus instead of) executing, redirect to // another page. return self::PRE_EXECUTE_PAGE_REDIRECT; } /** * {@inheritdoc} */ public function getExecuteRedirectUrl() { $ids = $this ->getSelectionIds(); if ( empty ( $ids ) === TRUE) { $ids [] = $this ->getParentId(); } // Redirect to the download controller, passing it the list of // entity IDs to download. return Url::fromRoute( Constants::ROUTE_DOWNLOAD, [ 'encoded' => implode( ',' , $ids ), ]); } /*-------------------------------------------------------------------- * * Execute. * *--------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function execute() { // Do nothing. This is never called because of the pre-execute redirect. } } |