@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 70 lines 1.8 kB view raw
1<?php 2 3final class PhabricatorSystemSelectViewAsController 4 extends PhabricatorController { 5 6 public function shouldRequireLogin() { 7 return false; 8 } 9 10 public function handleRequest(AphrontRequest $request) { 11 $viewer = $this->getViewer(); 12 $v_engine = $request->getStr('engine'); 13 14 if ($request->isFormPost()) { 15 $result = array('engine' => $v_engine); 16 return id(new AphrontAjaxResponse())->setContent($result); 17 } 18 19 $engines = PhabricatorDocumentEngine::getAllEngines(); 20 21 $options = $request->getStrList('options'); 22 $options = array_fuse($options); 23 24 // TODO: This controller is a bit rough because it isn't really using the 25 // file ref to figure out which engines should work. See also T13513. 26 // Callers can pass a list of "options" to control which options are 27 // presented, at least. 28 29 $ref = new PhabricatorDocumentRef(); 30 31 $map = array(); 32 foreach ($engines as $engine) { 33 $key = $engine->getDocumentEngineKey(); 34 35 if ($options && !isset($options[$key])) { 36 continue; 37 } 38 39 $label = $engine->getViewAsLabel($ref); 40 41 if (!strlen($label)) { 42 continue; 43 } 44 45 $map[$key] = $label; 46 } 47 48 asort($map); 49 50 $map = array( 51 '' => pht('(Use Default)'), 52 ) + $map; 53 54 $form = id(new AphrontFormView()) 55 ->setViewer($viewer) 56 ->appendRemarkupInstructions(pht('Choose a document engine to use.')) 57 ->appendChild( 58 id(new AphrontFormSelectControl()) 59 ->setLabel(pht('View As')) 60 ->setName('engine') 61 ->setValue($v_engine) 62 ->setOptions($map)); 63 64 return $this->newDialog() 65 ->setTitle(pht('Select Document Engine')) 66 ->appendForm($form) 67 ->addSubmitButton(pht('Choose Engine')) 68 ->addCancelButton('/'); 69 } 70}