@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Form MenuItem, Fix EditEngine Typeahead

Summary: Adds a FormEditEngine MenuItem for adding forms to Projects, Home, QuickCreate. Also adds an EditEngine typeahead that has token rendering issues currently.

Test Plan: Set a normal form as a menu item, edit it, set the name. Set a custom form as a menu item, edit it, set a name.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17098

+166 -5
+2
src/__phutil_library_map__.php
··· 2582 2582 'PhabricatorEditEngineExtensionModule' => 'applications/transactions/engineextension/PhabricatorEditEngineExtensionModule.php', 2583 2583 'PhabricatorEditEngineListController' => 'applications/transactions/controller/PhabricatorEditEngineListController.php', 2584 2584 'PhabricatorEditEnginePointsCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEnginePointsCommentAction.php', 2585 + 'PhabricatorEditEngineProfileMenuItem' => 'applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php', 2585 2586 'PhabricatorEditEngineQuery' => 'applications/transactions/query/PhabricatorEditEngineQuery.php', 2586 2587 'PhabricatorEditEngineSearchEngine' => 'applications/transactions/query/PhabricatorEditEngineSearchEngine.php', 2587 2588 'PhabricatorEditEngineSelectCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineSelectCommentAction.php', ··· 7571 7572 'PhabricatorEditEngineExtensionModule' => 'PhabricatorConfigModule', 7572 7573 'PhabricatorEditEngineListController' => 'PhabricatorEditEngineController', 7573 7574 'PhabricatorEditEnginePointsCommentAction' => 'PhabricatorEditEngineCommentAction', 7575 + 'PhabricatorEditEngineProfileMenuItem' => 'PhabricatorProfileMenuItem', 7574 7576 'PhabricatorEditEngineQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7575 7577 'PhabricatorEditEngineSearchEngine' => 'PhabricatorApplicationSearchEngine', 7576 7578 'PhabricatorEditEngineSelectCommentAction' => 'PhabricatorEditEngineCommentAction',
+122
src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php
··· 1 + <?php 2 + 3 + final class PhabricatorEditEngineProfileMenuItem 4 + extends PhabricatorProfileMenuItem { 5 + 6 + const MENUITEMKEY = 'editengine'; 7 + 8 + private $form; 9 + 10 + public function getMenuItemTypeIcon() { 11 + return 'fa-plus'; 12 + } 13 + 14 + public function getMenuItemTypeName() { 15 + return pht('Forms'); 16 + } 17 + 18 + public function canAddToObject($object) { 19 + return true; 20 + } 21 + 22 + public function attachForm($form) { 23 + $this->form = $form; 24 + return $this; 25 + } 26 + 27 + public function getForm() { 28 + $form = $this->form; 29 + if (!$form) { 30 + return null; 31 + } 32 + return $form; 33 + } 34 + 35 + public function willBuildNavigationItems(array $items) { 36 + $viewer = $this->getViewer(); 37 + $engines = PhabricatorEditEngine::getAllEditEngines(); 38 + $engine_keys = array_keys($engines); 39 + $forms = id(new PhabricatorEditEngineConfigurationQuery()) 40 + ->setViewer($viewer) 41 + ->withEngineKeys($engine_keys) 42 + ->withIsDisabled(false) 43 + ->execute(); 44 + $form_engines = mgroup($forms, 'getEngineKey'); 45 + $form_ids = $forms; 46 + 47 + $builtin_map = array(); 48 + foreach ($form_engines as $engine_key => $form_engine) { 49 + $builtin_map[$engine_key] = mpull($form_engine, null, 'getBuiltinKey'); 50 + } 51 + 52 + foreach ($items as $item) { 53 + $key = $item->getMenuItemProperty('formKey'); 54 + list($engine_key, $form_key) = explode('/', $key); 55 + if (is_numeric($form_key)) { 56 + $form = idx($form_ids, $form_key, null); 57 + $item->getMenuItem()->attachForm($form); 58 + } else if (isset($builtin_map[$engine_key][$form_key])) { 59 + $form = $builtin_map[$engine_key][$form_key]; 60 + $item->getMenuItem()->attachForm($form); 61 + } 62 + } 63 + } 64 + 65 + public function getDisplayName( 66 + PhabricatorProfileMenuItemConfiguration $config) { 67 + $form = $this->getForm(); 68 + if (!$form) { 69 + return pht('(Restricted/Invalid Form)'); 70 + } 71 + if (strlen($this->getName($config))) { 72 + return $this->getName($config); 73 + } else { 74 + return $form->getName(); 75 + } 76 + } 77 + 78 + public function buildEditEngineFields( 79 + PhabricatorProfileMenuItemConfiguration $config) { 80 + return array( 81 + id(new PhabricatorTextEditField()) 82 + ->setKey('name') 83 + ->setLabel(pht('Name')) 84 + ->setValue($this->getName($config)), 85 + id(new PhabricatorDatasourceEditField()) 86 + ->setKey('formKey') 87 + ->setLabel(pht('Form')) 88 + ->setDatasource(new PhabricatorEditEngineDatasource()) 89 + ->setSingleValue($config->getMenuItemProperty('formKey')), 90 + ); 91 + } 92 + 93 + private function getName( 94 + PhabricatorProfileMenuItemConfiguration $config) { 95 + return $config->getMenuItemProperty('name'); 96 + } 97 + 98 + protected function newNavigationMenuItems( 99 + PhabricatorProfileMenuItemConfiguration $config) { 100 + 101 + $form = $this->getForm(); 102 + if (!$form) { 103 + return array(); 104 + } 105 + $engine = $form->getEngine(); 106 + $form_key = $form->getIdentifier(); 107 + 108 + $icon = $form->getIcon(); 109 + $name = $this->getDisplayName($config); 110 + $href = $engine->getEditURI(null, "form/{$form_key}/"); 111 + 112 + $item = $this->newItem() 113 + ->setHref($href) 114 + ->setName($name) 115 + ->setIcon($icon); 116 + 117 + return array( 118 + $item, 119 + ); 120 + } 121 + 122 + }
+8 -1
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 49 49 } 50 50 51 51 final public function getEngineKey() { 52 - return $this->getPhobjectClassConstant('ENGINECONST', 64); 52 + $key = $this->getPhobjectClassConstant('ENGINECONST', 64); 53 + if (strpos($key, '/') !== false) { 54 + throw new Exception( 55 + pht( 56 + 'EditEngine ("%s") contains an invalid key character "/".', 57 + get_class($this))); 58 + } 59 + return $key; 53 60 } 54 61 55 62 final public function getApplication() {
+8
src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php
··· 109 109 return $this; 110 110 } 111 111 112 + public function setBuiltinKey($key) { 113 + if (strpos($key, '/') !== false) { 114 + throw new Exception( 115 + pht('EditEngine BuiltinKey contains an invalid key character "/".')); 116 + } 117 + return parent::setBuiltinKey($key); 118 + } 119 + 112 120 public function attachEngine(PhabricatorEditEngine $engine) { 113 121 $this->engine = $engine; 114 122 return $this;
+26 -4
src/applications/transactions/typeahead/PhabricatorEditEngineDatasource.php
··· 15 15 return 'PhabricatorTransactionsApplication'; 16 16 } 17 17 18 + protected function renderSpecialTokens(array $values) { 19 + return $this->renderTokensFromResults($this->buildResults(), $values); 20 + } 21 + 18 22 public function loadResults() { 23 + $results = $this->buildResults(); 24 + return $this->filterResultsAgainstTokens($results); 25 + } 26 + 27 + private function buildResults() { 19 28 $query = id(new PhabricatorEditEngineConfigurationQuery()); 20 29 21 30 $forms = $this->executeQuery($query); 22 31 $results = array(); 23 32 foreach ($forms as $form) { 24 - 33 + if ($form->getID()) { 34 + $key = $form->getEngineKey().'/'.$form->getID(); 35 + } else { 36 + $key = $form->getEngineKey().'/'.$form->getBuiltinKey(); 37 + } 25 38 $result = id(new PhabricatorTypeaheadResult()) 26 39 ->setName($form->getName()) 27 - ->setPHID($form->getPHID()); 40 + ->setPHID($key) 41 + ->setIcon($form->getIcon()); 28 42 29 43 if ($form->getIsDisabled()) { 30 44 $result->setClosed(pht('Archived')); 31 45 } 32 46 33 - $results[] = $result; 47 + if ($form->getIsDefault()) { 48 + $result->addAttribute(pht('Create Form')); 49 + } 50 + 51 + if ($form->getIsEdit()) { 52 + $result->addAttribute(pht('Edit Form')); 53 + } 54 + 55 + $results[$key] = $result; 34 56 } 35 57 36 - return $this->filterResultsAgainstTokens($results); 58 + return $results; 37 59 } 38 60 39 61 }