@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.

Modularize global quick create builtin items

Summary: Ref T5867. Instead of hard-coding projects, tasks and repositories, let EditEngines say "I want a quick create item" so third-party code can also hook into the menu without upstream changes.

Test Plan: Saw same default items in menu.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T5867

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

+51 -112
-2
src/__phutil_library_map__.php
··· 2668 2668 'PhabricatorFactSpec' => 'applications/fact/spec/PhabricatorFactSpec.php', 2669 2669 'PhabricatorFactUpdateIterator' => 'applications/fact/extract/PhabricatorFactUpdateIterator.php', 2670 2670 'PhabricatorFavoritesApplication' => 'applications/favorites/application/PhabricatorFavoritesApplication.php', 2671 - 'PhabricatorFavoritesConstants' => 'applications/favorites/constants/PhabricatorFavoritesConstants.php', 2672 2671 'PhabricatorFavoritesController' => 'applications/favorites/controller/PhabricatorFavoritesController.php', 2673 2672 'PhabricatorFavoritesMainController' => 'applications/favorites/controller/PhabricatorFavoritesMainController.php', 2674 2673 'PhabricatorFavoritesMenuItemController' => 'applications/favorites/controller/PhabricatorFavoritesMenuItemController.php', ··· 7683 7682 'PhabricatorFactSpec' => 'Phobject', 7684 7683 'PhabricatorFactUpdateIterator' => 'PhutilBufferedIterator', 7685 7684 'PhabricatorFavoritesApplication' => 'PhabricatorApplication', 7686 - 'PhabricatorFavoritesConstants' => 'PhabricatorFavoritesController', 7687 7685 'PhabricatorFavoritesController' => 'PhabricatorController', 7688 7686 'PhabricatorFavoritesMainController' => 'PhabricatorFavoritesController', 7689 7687 'PhabricatorFavoritesMenuItemController' => 'PhabricatorFavoritesController',
+4
src/applications/diffusion/editor/DiffusionRepositoryEditEngine.php
··· 20 20 return false; 21 21 } 22 22 23 + public function isDefaultQuickCreateEngine() { 24 + return true; 25 + } 26 + 23 27 public function getEngineName() { 24 28 return pht('Repositories'); 25 29 }
-11
src/applications/favorites/constants/PhabricatorFavoritesConstants.php
··· 1 - <?php 2 - 3 - final class PhabricatorFavoritesConstants 4 - extends PhabricatorFavoritesController { 5 - 6 - const ITEM_TASK = 'favorites.task'; 7 - const ITEM_PROJECT = 'favorites.project'; 8 - const ITEM_REPOSITORY = 'favorites.repository'; 9 - const ITEM_DIVIDER = 'favorites.divider'; 10 - 11 - }
+16 -29
src/applications/favorites/engine/PhabricatorFavoritesProfileMenuEngine.php
··· 22 22 $items = array(); 23 23 $viewer = $this->getViewer(); 24 24 25 - $create_task = array( 26 - 'name' => null, 27 - 'formKey' => 28 - id(new ManiphestEditEngine())->getProfileMenuItemDefault(), 29 - ); 25 + $engines = PhabricatorEditEngine::getAllEditEngines(); 26 + $engines = msortv($engines, 'getQuickCreateOrderVector'); 30 27 31 - $create_project = array( 32 - 'name' => null, 33 - 'formKey' => 34 - id(new PhabricatorProjectEditEngine())->getProfileMenuItemDefault(), 35 - ); 28 + foreach ($engines as $engine) { 29 + foreach ($engine->getDefaultQuickCreateFormKeys() as $form_key) { 30 + $form_hash = PhabricatorHash::digestForIndex($form_key); 31 + $builtin_key = "editengine.form({$form_hash})"; 36 32 37 - $create_repository = array( 38 - 'name' => null, 39 - 'formKey' => 40 - id(new DiffusionRepositoryEditEngine())->getProfileMenuItemDefault(), 41 - ); 33 + $properties = array( 34 + 'name' => null, 35 + 'formKey' => $form_key, 36 + ); 42 37 43 - $items[] = $this->newItem() 44 - ->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_TASK) 45 - ->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY) 46 - ->setMenuItemProperties($create_task); 47 - 48 - $items[] = $this->newItem() 49 - ->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_PROJECT) 50 - ->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY) 51 - ->setMenuItemProperties($create_project); 52 - 53 - $items[] = $this->newItem() 54 - ->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_REPOSITORY) 55 - ->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY) 56 - ->setMenuItemProperties($create_repository); 38 + $items[] = $this->newItem() 39 + ->setBuiltinKey($builtin_key) 40 + ->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY) 41 + ->setMenuItemProperties($properties); 42 + } 43 + } 57 44 58 45 return $items; 59 46 }
+4
src/applications/maniphest/editor/ManiphestEditEngine.php
··· 21 21 return 'PhabricatorManiphestApplication'; 22 22 } 23 23 24 + public function isDefaultQuickCreateEngine() { 25 + return true; 26 + } 27 + 24 28 protected function newEditableObject() { 25 29 return ManiphestTask::initializeNewTask($this->getViewer()); 26 30 }
+4
src/applications/project/engine/PhabricatorProjectEditEngine.php
··· 26 26 return $this->milestoneProject; 27 27 } 28 28 29 + public function isDefaultQuickCreateEngine() { 30 + return true; 31 + } 32 + 29 33 public function getEngineName() { 30 34 return pht('Projects'); 31 35 }
+23 -70
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 77 77 return true; 78 78 } 79 79 80 + public function isDefaultQuickCreateEngine() { 81 + return false; 82 + } 83 + 84 + public function getDefaultQuickCreateFormKeys() { 85 + $keys = array(); 86 + 87 + if ($this->isDefaultQuickCreateEngine()) { 88 + $keys[] = self::EDITENGINECONFIG_DEFAULT; 89 + } 90 + 91 + foreach ($keys as $idx => $key) { 92 + $keys[$idx] = $this->getEngineKey().'/'.$key; 93 + } 94 + 95 + return $keys; 96 + } 97 + 98 + public function getQuickCreateOrderVector() { 99 + return id(new PhutilSortVector()) 100 + ->addString($this->getObjectCreateShortText()); 101 + } 102 + 80 103 /** 81 104 * Force the engine to edit a particular object. 82 105 */ ··· 105 128 106 129 public function getHideHeader() { 107 130 return $this->hideHeader; 108 - } 109 - 110 - public function getProfileMenuItemDefault() { 111 - return $this->getEngineKey().'/'.self::EDITENGINECONFIG_DEFAULT; 112 131 } 113 132 114 133 ··· 280 299 */ 281 300 protected function getCommentViewButtonText($object) { 282 301 return $this->getCommentViewSeriousButtonText($object); 283 - } 284 - 285 - 286 - /** 287 - * @task text 288 - */ 289 - protected function getQuickCreateMenuHeaderText() { 290 - return $this->getObjectCreateShortText(); 291 302 } 292 303 293 304 ··· 2100 2111 return $application->getIcon(); 2101 2112 } 2102 2113 2103 - public function hasQuickCreateActions() { 2104 - if (!$this->isEngineConfigurable()) { 2105 - return false; 2106 - } 2107 - 2108 - return true; 2109 - } 2110 - 2111 - public function newQuickCreateActions(array $configs) { 2112 - $items = array(); 2113 - 2114 - if (!$configs) { 2115 - return array(); 2116 - } 2117 - 2118 - // If the viewer is logged in and can't create objects, don't show the 2119 - // menu item. If they're logged out, we assume they could create objects 2120 - // if they logged in, so we show the item as a hint about how to 2121 - // accomplish the action. 2122 - if ($this->getViewer()->isLoggedIn()) { 2123 - if (!$this->hasCreateCapability()) { 2124 - return array(); 2125 - } 2126 - } 2127 - 2128 - if (count($configs) == 1) { 2129 - $config = head($configs); 2130 - $items[] = $this->newQuickCreateAction($config); 2131 - } else { 2132 - $group_name = $this->getQuickCreateMenuHeaderText(); 2133 - 2134 - $items[] = id(new PHUIListItemView()) 2135 - ->setType(PHUIListItemView::TYPE_LABEL) 2136 - ->setName($group_name); 2137 - 2138 - foreach ($configs as $config) { 2139 - $items[] = $this->newQuickCreateAction($config) 2140 - ->setIndented(true); 2141 - } 2142 - } 2143 - 2144 - return $items; 2145 - } 2146 - 2147 2114 private function loadUsableConfigurationsForCreate() { 2148 2115 $viewer = $this->getViewer(); 2149 2116 ··· 2157 2124 $configs = msort($configs, 'getCreateSortKey'); 2158 2125 2159 2126 return $configs; 2160 - } 2161 - 2162 - private function newQuickCreateAction( 2163 - PhabricatorEditEngineConfiguration $config) { 2164 - 2165 - $item_name = $config->getName(); 2166 - $item_icon = $config->getIcon(); 2167 - $form_key = $config->getIdentifier(); 2168 - $item_uri = $this->getEditURI(null, "form/{$form_key}/"); 2169 - 2170 - return id(new PHUIListItemView()) 2171 - ->setName($item_name) 2172 - ->setIcon($item_icon) 2173 - ->setHref($item_uri); 2174 2127 } 2175 2128 2176 2129 protected function getValidationExceptionShortMessage(