@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 102 lines 2.9 kB view raw
1<?php 2 3final class DrydockBlueprintEditController extends DrydockBlueprintController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $engine = id(new DrydockBlueprintEditEngine()) 7 ->setController($this); 8 9 $id = $request->getURIData('id'); 10 if (!$id) { 11 $this->requireApplicationCapability( 12 DrydockCreateBlueprintsCapability::CAPABILITY); 13 14 $type = $request->getStr('blueprintType'); 15 16 $impl = DrydockBlueprintImplementation::getNamedImplementation($type); 17 if (!$impl || !$impl->isEnabled()) { 18 return $this->buildTypeSelectionResponse(); 19 } 20 21 $engine 22 ->addContextParameter('blueprintType', $type) 23 ->setBlueprintImplementation($impl); 24 } 25 26 return $engine->buildResponse(); 27 } 28 29 private function buildTypeSelectionResponse() { 30 $request = $this->getRequest(); 31 $viewer = $this->getViewer(); 32 33 $implementations = 34 DrydockBlueprintImplementation::getAllBlueprintImplementations(); 35 36 $errors = array(); 37 $e_blueprint = null; 38 39 if ($request->isFormPost()) { 40 $class = $request->getStr('blueprintType'); 41 if (!isset($implementations[$class])) { 42 $e_blueprint = pht('Required'); 43 $errors[] = pht('You must choose a blueprint type.'); 44 } 45 } 46 47 $control = id(new AphrontFormRadioButtonControl()) 48 ->setName('blueprintType') 49 ->setLabel(pht('Blueprint Type')) 50 ->setError($e_blueprint); 51 52 foreach ($implementations as $implementation_name => $implementation) { 53 $disabled = !$implementation->isEnabled(); 54 55 $impl_icon = $implementation->getBlueprintIcon(); 56 $impl_name = $implementation->getBlueprintName(); 57 58 $impl_icon = id(new PHUIIconView()) 59 ->setIcon($impl_icon, 'lightgreytext'); 60 61 $control->addButton( 62 $implementation_name, 63 array($impl_icon, ' ', $impl_name), 64 array( 65 pht('Provides: %s', $implementation->getType()), 66 phutil_tag('br'), 67 phutil_tag('br'), 68 $implementation->getDescription(), 69 ), 70 $disabled ? 'disabled' : null, 71 $disabled); 72 } 73 74 $title = pht('Create New Blueprint'); 75 $crumbs = $this->buildApplicationCrumbs(); 76 $crumbs->addTextCrumb(pht('New Blueprint')); 77 $crumbs->setBorder(true); 78 79 $form = id(new AphrontFormView()) 80 ->setUser($viewer) 81 ->appendChild($control) 82 ->appendChild( 83 id(new AphrontFormSubmitControl()) 84 ->addCancelButton($this->getApplicationURI('blueprint/')) 85 ->setValue(pht('Continue'))); 86 87 $box = id(new PHUIObjectBoxView()) 88 ->setFormErrors($errors) 89 ->setHeaderText($title) 90 ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) 91 ->setForm($form); 92 93 $view = id(new PHUITwoColumnView()) 94 ->setFooter($box); 95 96 return $this->newPage() 97 ->setTitle($title) 98 ->setCrumbs($crumbs) 99 ->appendChild($view); 100 } 101 102}