foldershare-8.x-1.2/src/Plugin/FolderShareCommand/Edit.php
src/Plugin/FolderShareCommand/Edit.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 99 100 | <?php namespace Drupal\foldershare\Plugin\FolderShareCommand; use Drupal\Core\Url; use Drupal\foldershare\Constants; /** * Defines a command plugin to edit an entity. * * The command is a dummy that does not use a configuration and does not * execute to change the entity. Instead, this command is used solely to * create an entry in command menus and support a redirect to a stand-alone * edit form from which the user can alter fields on the entity. * * Configuration parameters: * - 'parentId': the parent folder, if any. * - 'selectionIds': selected entities to edit. * * @ingroup foldershare * * @FolderShareCommand( * id = "foldersharecommand_edit", * label = @Translation("Edit"), * menuNameDefault = @Translation("Edit..."), * menuName = @Translation("Edit..."), * description = @Translation("Edit the fields of a selected item."), * category = "edit", * weight = 10, * parentConstraints = { * "kinds" = { * "rootlist", * "any", * }, * "access" = "view", * }, * selectionConstraints = { * "types" = { * "parent", * "one", * }, * "kinds" = { * "any", * }, * "access" = "update", * }, * ) */ class Edit 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) { $id = $this ->getParentId(); } else { $id = reset( $ids ); } // Redirect to the edit form for the single entity being edited. return Url::fromRoute( Constants::ROUTE_FOLDERSHARE_EDIT, [ Constants::ROUTE_FOLDERSHARE_ID => $id , ]); } /*-------------------------------------------------------------------- * * Execute. * *--------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function execute() { // Do nothing. This is never called because of the pre-execute redirect. } } |