@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 69 lines 1.9 kB view raw
1<?php 2 3final class PassphraseCredentialCreateController extends PassphraseController { 4 5 public function handleRequest(AphrontRequest $request) { 6 $viewer = $request->getViewer(); 7 8 $types = PassphraseCredentialType::getAllCreateableTypes(); 9 $types = mpull($types, null, 'getCredentialType'); 10 $types = msort($types, 'getCredentialTypeName'); 11 12 $errors = array(); 13 $e_type = null; 14 15 if ($request->isFormPost()) { 16 $type = $request->getStr('type'); 17 if ($type === null || empty($types[$type])) { 18 $errors[] = pht('You must choose a credential type.'); 19 $e_type = pht('Required'); 20 } 21 22 if (!$errors) { 23 $uri = $this->getApplicationURI('edit/?type='.$type); 24 return id(new AphrontRedirectResponse())->setURI($uri); 25 } 26 } 27 28 $types_control = id(new AphrontFormRadioButtonControl()) 29 ->setName('type') 30 ->setLabel(pht('Credential Type')) 31 ->setError($e_type); 32 33 foreach ($types as $type) { 34 $types_control->addButton( 35 $type->getCredentialType(), 36 $type->getCredentialTypeName(), 37 $type->getCredentialTypeDescription()); 38 } 39 40 $form = id(new AphrontFormView()) 41 ->setUser($viewer) 42 ->appendChild($types_control) 43 ->appendChild( 44 id(new AphrontFormSubmitControl()) 45 ->setValue(pht('Continue')) 46 ->addCancelButton($this->getApplicationURI())); 47 48 $title = pht('New Credential'); 49 50 $crumbs = $this->buildApplicationCrumbs(); 51 $crumbs->addTextCrumb(pht('Create')); 52 $crumbs->setBorder(true); 53 54 $box = id(new PHUIObjectBoxView()) 55 ->setHeaderText($title) 56 ->setFormErrors($errors) 57 ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) 58 ->setForm($form); 59 60 $view = id(new PHUITwoColumnView()) 61 ->setFooter($box); 62 63 return $this->newPage() 64 ->setTitle($title) 65 ->setCrumbs($crumbs) 66 ->appendChild($view); 67 } 68 69}