mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
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
This commit is contained in:
parent
a886969c48
commit
9d3f09ab47
7 changed files with 51 additions and 112 deletions
|
@ -2668,7 +2668,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFactSpec' => 'applications/fact/spec/PhabricatorFactSpec.php',
|
||||
'PhabricatorFactUpdateIterator' => 'applications/fact/extract/PhabricatorFactUpdateIterator.php',
|
||||
'PhabricatorFavoritesApplication' => 'applications/favorites/application/PhabricatorFavoritesApplication.php',
|
||||
'PhabricatorFavoritesConstants' => 'applications/favorites/constants/PhabricatorFavoritesConstants.php',
|
||||
'PhabricatorFavoritesController' => 'applications/favorites/controller/PhabricatorFavoritesController.php',
|
||||
'PhabricatorFavoritesMainController' => 'applications/favorites/controller/PhabricatorFavoritesMainController.php',
|
||||
'PhabricatorFavoritesMenuItemController' => 'applications/favorites/controller/PhabricatorFavoritesMenuItemController.php',
|
||||
|
@ -7683,7 +7682,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFactSpec' => 'Phobject',
|
||||
'PhabricatorFactUpdateIterator' => 'PhutilBufferedIterator',
|
||||
'PhabricatorFavoritesApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorFavoritesConstants' => 'PhabricatorFavoritesController',
|
||||
'PhabricatorFavoritesController' => 'PhabricatorController',
|
||||
'PhabricatorFavoritesMainController' => 'PhabricatorFavoritesController',
|
||||
'PhabricatorFavoritesMenuItemController' => 'PhabricatorFavoritesController',
|
||||
|
|
|
@ -20,6 +20,10 @@ final class DiffusionRepositoryEditEngine
|
|||
return false;
|
||||
}
|
||||
|
||||
public function isDefaultQuickCreateEngine() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Repositories');
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFavoritesConstants
|
||||
extends PhabricatorFavoritesController {
|
||||
|
||||
const ITEM_TASK = 'favorites.task';
|
||||
const ITEM_PROJECT = 'favorites.project';
|
||||
const ITEM_REPOSITORY = 'favorites.repository';
|
||||
const ITEM_DIVIDER = 'favorites.divider';
|
||||
|
||||
}
|
|
@ -22,38 +22,25 @@ final class PhabricatorFavoritesProfileMenuEngine
|
|||
$items = array();
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$create_task = array(
|
||||
'name' => null,
|
||||
'formKey' =>
|
||||
id(new ManiphestEditEngine())->getProfileMenuItemDefault(),
|
||||
);
|
||||
$engines = PhabricatorEditEngine::getAllEditEngines();
|
||||
$engines = msortv($engines, 'getQuickCreateOrderVector');
|
||||
|
||||
$create_project = array(
|
||||
'name' => null,
|
||||
'formKey' =>
|
||||
id(new PhabricatorProjectEditEngine())->getProfileMenuItemDefault(),
|
||||
);
|
||||
foreach ($engines as $engine) {
|
||||
foreach ($engine->getDefaultQuickCreateFormKeys() as $form_key) {
|
||||
$form_hash = PhabricatorHash::digestForIndex($form_key);
|
||||
$builtin_key = "editengine.form({$form_hash})";
|
||||
|
||||
$create_repository = array(
|
||||
$properties = array(
|
||||
'name' => null,
|
||||
'formKey' =>
|
||||
id(new DiffusionRepositoryEditEngine())->getProfileMenuItemDefault(),
|
||||
'formKey' => $form_key,
|
||||
);
|
||||
|
||||
$items[] = $this->newItem()
|
||||
->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_TASK)
|
||||
->setBuiltinKey($builtin_key)
|
||||
->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY)
|
||||
->setMenuItemProperties($create_task);
|
||||
|
||||
$items[] = $this->newItem()
|
||||
->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_PROJECT)
|
||||
->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY)
|
||||
->setMenuItemProperties($create_project);
|
||||
|
||||
$items[] = $this->newItem()
|
||||
->setBuiltinKey(PhabricatorFavoritesConstants::ITEM_REPOSITORY)
|
||||
->setMenuItemKey(PhabricatorEditEngineProfileMenuItem::MENUITEMKEY)
|
||||
->setMenuItemProperties($create_repository);
|
||||
->setMenuItemProperties($properties);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,10 @@ final class ManiphestEditEngine
|
|||
return 'PhabricatorManiphestApplication';
|
||||
}
|
||||
|
||||
public function isDefaultQuickCreateEngine() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function newEditableObject() {
|
||||
return ManiphestTask::initializeNewTask($this->getViewer());
|
||||
}
|
||||
|
|
|
@ -26,6 +26,10 @@ final class PhabricatorProjectEditEngine
|
|||
return $this->milestoneProject;
|
||||
}
|
||||
|
||||
public function isDefaultQuickCreateEngine() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Projects');
|
||||
}
|
||||
|
|
|
@ -77,6 +77,29 @@ abstract class PhabricatorEditEngine
|
|||
return true;
|
||||
}
|
||||
|
||||
public function isDefaultQuickCreateEngine() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDefaultQuickCreateFormKeys() {
|
||||
$keys = array();
|
||||
|
||||
if ($this->isDefaultQuickCreateEngine()) {
|
||||
$keys[] = self::EDITENGINECONFIG_DEFAULT;
|
||||
}
|
||||
|
||||
foreach ($keys as $idx => $key) {
|
||||
$keys[$idx] = $this->getEngineKey().'/'.$key;
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
public function getQuickCreateOrderVector() {
|
||||
return id(new PhutilSortVector())
|
||||
->addString($this->getObjectCreateShortText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the engine to edit a particular object.
|
||||
*/
|
||||
|
@ -107,10 +130,6 @@ abstract class PhabricatorEditEngine
|
|||
return $this->hideHeader;
|
||||
}
|
||||
|
||||
public function getProfileMenuItemDefault() {
|
||||
return $this->getEngineKey().'/'.self::EDITENGINECONFIG_DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
/* -( Managing Fields )---------------------------------------------------- */
|
||||
|
||||
|
@ -283,14 +302,6 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task text
|
||||
*/
|
||||
protected function getQuickCreateMenuHeaderText() {
|
||||
return $this->getObjectCreateShortText();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a human-readable header describing what this engine is used to do,
|
||||
* like "Configure Maniphest Task Forms".
|
||||
|
@ -2100,50 +2111,6 @@ abstract class PhabricatorEditEngine
|
|||
return $application->getIcon();
|
||||
}
|
||||
|
||||
public function hasQuickCreateActions() {
|
||||
if (!$this->isEngineConfigurable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function newQuickCreateActions(array $configs) {
|
||||
$items = array();
|
||||
|
||||
if (!$configs) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// If the viewer is logged in and can't create objects, don't show the
|
||||
// menu item. If they're logged out, we assume they could create objects
|
||||
// if they logged in, so we show the item as a hint about how to
|
||||
// accomplish the action.
|
||||
if ($this->getViewer()->isLoggedIn()) {
|
||||
if (!$this->hasCreateCapability()) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
if (count($configs) == 1) {
|
||||
$config = head($configs);
|
||||
$items[] = $this->newQuickCreateAction($config);
|
||||
} else {
|
||||
$group_name = $this->getQuickCreateMenuHeaderText();
|
||||
|
||||
$items[] = id(new PHUIListItemView())
|
||||
->setType(PHUIListItemView::TYPE_LABEL)
|
||||
->setName($group_name);
|
||||
|
||||
foreach ($configs as $config) {
|
||||
$items[] = $this->newQuickCreateAction($config)
|
||||
->setIndented(true);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function loadUsableConfigurationsForCreate() {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
|
@ -2159,20 +2126,6 @@ abstract class PhabricatorEditEngine
|
|||
return $configs;
|
||||
}
|
||||
|
||||
private function newQuickCreateAction(
|
||||
PhabricatorEditEngineConfiguration $config) {
|
||||
|
||||
$item_name = $config->getName();
|
||||
$item_icon = $config->getIcon();
|
||||
$form_key = $config->getIdentifier();
|
||||
$item_uri = $this->getEditURI(null, "form/{$form_key}/");
|
||||
|
||||
return id(new PHUIListItemView())
|
||||
->setName($item_name)
|
||||
->setIcon($item_icon)
|
||||
->setHref($item_uri);
|
||||
}
|
||||
|
||||
protected function getValidationExceptionShortMessage(
|
||||
PhabricatorApplicationTransactionValidationException $ex,
|
||||
PhabricatorEditField $field) {
|
||||
|
|
Loading…
Reference in a new issue