@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 recaptime-dev/main 92 lines 2.7 kB view raw
1<?php 2 3final class HarbormasterPlanBehaviorController 4 extends HarbormasterPlanController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $this->getViewer(); 8 9 $plan = id(new HarbormasterBuildPlanQuery()) 10 ->setViewer($viewer) 11 ->withIDs(array($request->getURIData('id'))) 12 ->requireCapabilities( 13 array( 14 PhabricatorPolicyCapability::CAN_VIEW, 15 PhabricatorPolicyCapability::CAN_EDIT, 16 )) 17 ->executeOne(); 18 if (!$plan) { 19 return new Aphront404Response(); 20 } 21 22 $behavior_key = $request->getURIData('behaviorKey'); 23 $metadata_key = HarbormasterBuildPlanBehavior::getTransactionMetadataKey(); 24 25 $behaviors = HarbormasterBuildPlanBehavior::newPlanBehaviors(); 26 $behavior = idx($behaviors, $behavior_key); 27 if (!$behavior) { 28 return new Aphront404Response(); 29 } 30 31 $plan_uri = $plan->getURI(); 32 33 $v_option = $behavior->getPlanOption($plan)->getKey(); 34 if ($request->isFormPost()) { 35 $v_option = $request->getStr('option'); 36 37 $xactions = array(); 38 39 $xactions[] = id(new HarbormasterBuildPlanTransaction()) 40 ->setTransactionType( 41 HarbormasterBuildPlanBehaviorTransaction::TRANSACTIONTYPE) 42 ->setMetadataValue($metadata_key, $behavior_key) 43 ->setNewValue($v_option); 44 45 $editor = id(new HarbormasterBuildPlanEditor()) 46 ->setActor($viewer) 47 ->setContinueOnNoEffect(true) 48 ->setContinueOnMissingFields(true) 49 ->setContentSourceFromRequest($request); 50 51 $editor->applyTransactions($plan, $xactions); 52 53 return id(new AphrontRedirectResponse())->setURI($plan_uri); 54 } 55 56 $select_control = id(new AphrontFormRadioButtonControl()) 57 ->setName('option') 58 ->setValue($v_option) 59 ->setLabel(pht('Option')); 60 61 foreach ($behavior->getOptions() as $option) { 62 $icon = id(new PHUIIconView()) 63 ->setIcon($option->getIcon()); 64 65 $select_control->addButton( 66 $option->getKey(), 67 array( 68 $icon, 69 ' ', 70 $option->getName(), 71 ), 72 $option->getDescription()); 73 } 74 75 $form = id(new AphrontFormView()) 76 ->setViewer($viewer) 77 ->appendInstructions( 78 pht( 79 'Choose a build plan behavior for "%s".', 80 phutil_tag('strong', array(), $behavior->getName()))) 81 ->appendRemarkupInstructions($behavior->getEditInstructions()) 82 ->appendControl($select_control); 83 84 return $this->newDialog() 85 ->setTitle(pht('Edit Behavior: %s', $behavior->getName())) 86 ->appendForm($form) 87 ->setWidth(AphrontDialogView::WIDTH_FORM) 88 ->addSubmitButton(pht('Save Changes')) 89 ->addCancelButton($plan_uri); 90 } 91 92}