foldershare-8.x-1.2/src/Plugin/FolderShareCommand/Duplicate.php
src/Plugin/FolderShareCommand/Duplicate.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 | <?php namespace Drupal\foldershare\Plugin\FolderShareCommand; use Drupal\foldershare\Settings; use Drupal\foldershare\Entity\FolderShare; /** * Defines a command plugin to duplicate a file or folder. * * The command copies all selected entities and adds them back into the * same parent folder or root folder list. Duplication recurses through * all folder content as well. * * Configuration parameters: * - 'parentId': the parent folder, if any. * - 'selectionIds': selected entities to duplicate. * * @ingroup foldershare * * @FolderShareCommand( * id = "foldersharecommand_duplicate", * label = @Translation("Duplicate"), * menuNameDefault = @Translation("Duplicate"), * menuName = @Translation("Duplicate"), * description = @Translation("Duplicate selected files and folders to create a copy in the current location."), * category = "copy & move", * weight = 20, * parentConstraints = { * "kinds" = { * "rootlist", * "folder", * }, * "access" = "create", * }, * selectionConstraints = { * "types" = { * "one", * "many", * }, * "kinds" = { * "any", * }, * "access" = "view", * }, * ) */ class Duplicate extends FolderShareCommandBase { /*-------------------------------------------------------------------- * * Execute. * *--------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function execute() { $ids = $this ->getSelectionIds(); try { FolderShare::duplicateMultiple( $ids ); } catch (\Exception $e ) { \Drupal::messenger()->addMessage( $e ->getMessage(), 'error' ); } if (Settings::getCommandNormalCompletionReportEnable() === TRUE) { \Drupal::messenger()->addMessage( \Drupal::translation()->formatPlural( count ( $ids ), "The item has been duplicated." , "@count items have been duplicated." ), 'status' ); } } } |