@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 120 lines 3.3 kB view raw
1<?php 2 3final class PhabricatorEditEngineConfigurationLockController 4 extends PhabricatorEditEngineController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $engine_key = $request->getURIData('engineKey'); 8 $this->setEngineKey($engine_key); 9 10 $key = $request->getURIData('key'); 11 $viewer = $this->getViewer(); 12 13 $config = id(new PhabricatorEditEngineConfigurationQuery()) 14 ->setViewer($viewer) 15 ->withEngineKeys(array($engine_key)) 16 ->withIdentifiers(array($key)) 17 ->requireCapabilities( 18 array( 19 PhabricatorPolicyCapability::CAN_VIEW, 20 PhabricatorPolicyCapability::CAN_EDIT, 21 )) 22 ->executeOne(); 23 if (!$config) { 24 return id(new Aphront404Response()); 25 } 26 27 $cancel_uri = "/transactions/editengine/{$engine_key}/view/{$key}/"; 28 29 if ($request->isFormPost()) { 30 $xactions = array(); 31 32 $locks = $request->getArr('locks'); 33 $type_locks = PhabricatorEditEngineLocksTransaction::TRANSACTIONTYPE; 34 $xactions[] = id(new PhabricatorEditEngineConfigurationTransaction()) 35 ->setTransactionType($type_locks) 36 ->setNewValue($locks); 37 38 $editor = id(new PhabricatorEditEngineConfigurationEditor()) 39 ->setActor($viewer) 40 ->setContentSourceFromRequest($request) 41 ->setContinueOnMissingFields(true) 42 ->setContinueOnNoEffect(true); 43 44 $editor->applyTransactions($config, $xactions); 45 46 return id(new AphrontRedirectResponse()) 47 ->setURI($cancel_uri); 48 } 49 50 $engine = $config->getEngine(); 51 $fields = $engine->getFieldsForConfig($config); 52 53 $help = pht(<<<EOTEXT 54**Locked** fields are visible in the form, but their values can not be changed 55by the user. 56 57**Hidden** fields are not visible in the form. 58 59Any assigned default values are still respected, even if the field is locked 60or hidden. 61EOTEXT 62 ); 63 64 $form = id(new AphrontFormView()) 65 ->setUser($viewer) 66 ->appendRemarkupInstructions($help); 67 68 $locks = $config->getFieldLocks(); 69 70 $lock_visible = PhabricatorEditEngineConfiguration::LOCK_VISIBLE; 71 $lock_locked = PhabricatorEditEngineConfiguration::LOCK_LOCKED; 72 $lock_hidden = PhabricatorEditEngineConfiguration::LOCK_HIDDEN; 73 74 $map = array( 75 $lock_visible => pht('Visible'), 76 $lock_locked => pht("\xF0\x9F\x94\x92 Locked"), 77 $lock_hidden => pht("\xE2\x9C\x98 Hidden"), 78 ); 79 80 foreach ($fields as $field) { 81 if (!$field->getIsFormField()) { 82 continue; 83 } 84 85 if (!$field->getIsLockable()) { 86 continue; 87 } 88 89 $key = $field->getKey(); 90 91 $label = $field->getLabel(); 92 if (!strlen($label)) { 93 $label = $key; 94 } 95 96 if ($field->getIsHidden()) { 97 $value = $lock_hidden; 98 } else if ($field->getIsLocked()) { 99 $value = $lock_locked; 100 } else { 101 $value = $lock_visible; 102 } 103 104 $form->appendControl( 105 id(new AphrontFormSelectControl()) 106 ->setName('locks['.$key.']') 107 ->setLabel($label) 108 ->setValue($value) 109 ->setOptions($map)); 110 } 111 112 return $this->newDialog() 113 ->setTitle(pht('Lock / Hide Fields')) 114 ->setWidth(AphrontDialogView::WIDTH_FORM) 115 ->appendForm($form) 116 ->addSubmitButton(pht('Save Changes')) 117 ->addCancelButton($cancel_uri); 118 } 119 120}