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

Convert Nuance Sources to EditEngine

Summary: Ref T10537. Converts sources to EditEngine.

Test Plan:
- Created a new source.
- Edited an existing source.
- Submitted a complaint with the complaint form.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10537

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

+234 -378
+2 -2
src/__phutil_library_map__.php
··· 1460 1460 'NuanceSource' => 'applications/nuance/storage/NuanceSource.php', 1461 1461 'NuanceSourceActionController' => 'applications/nuance/controller/NuanceSourceActionController.php', 1462 1462 'NuanceSourceController' => 'applications/nuance/controller/NuanceSourceController.php', 1463 - 'NuanceSourceCreateController' => 'applications/nuance/controller/NuanceSourceCreateController.php', 1464 1463 'NuanceSourceDefaultEditCapability' => 'applications/nuance/capability/NuanceSourceDefaultEditCapability.php', 1465 1464 'NuanceSourceDefaultViewCapability' => 'applications/nuance/capability/NuanceSourceDefaultViewCapability.php', 1466 1465 'NuanceSourceDefinition' => 'applications/nuance/source/NuanceSourceDefinition.php', 1467 1466 'NuanceSourceDefinitionTestCase' => 'applications/nuance/source/__tests__/NuanceSourceDefinitionTestCase.php', 1468 1467 'NuanceSourceEditController' => 'applications/nuance/controller/NuanceSourceEditController.php', 1468 + 'NuanceSourceEditEngine' => 'applications/nuance/editor/NuanceSourceEditEngine.php', 1469 1469 'NuanceSourceEditor' => 'applications/nuance/editor/NuanceSourceEditor.php', 1470 1470 'NuanceSourceListController' => 'applications/nuance/controller/NuanceSourceListController.php', 1471 1471 'NuanceSourceManageCapability' => 'applications/nuance/capability/NuanceSourceManageCapability.php', ··· 5716 5716 ), 5717 5717 'NuanceSourceActionController' => 'NuanceController', 5718 5718 'NuanceSourceController' => 'NuanceController', 5719 - 'NuanceSourceCreateController' => 'NuanceSourceController', 5720 5719 'NuanceSourceDefaultEditCapability' => 'PhabricatorPolicyCapability', 5721 5720 'NuanceSourceDefaultViewCapability' => 'PhabricatorPolicyCapability', 5722 5721 'NuanceSourceDefinition' => 'Phobject', 5723 5722 'NuanceSourceDefinitionTestCase' => 'PhabricatorTestCase', 5724 5723 'NuanceSourceEditController' => 'NuanceSourceController', 5724 + 'NuanceSourceEditEngine' => 'PhabricatorEditEngine', 5725 5725 'NuanceSourceEditor' => 'PhabricatorApplicationTransactionEditor', 5726 5726 'NuanceSourceListController' => 'NuanceSourceController', 5727 5727 'NuanceSourceManageCapability' => 'PhabricatorPolicyCapability',
+1 -4
src/applications/nuance/application/PhabricatorNuanceApplication.php
··· 46 46 ), 47 47 'source/' => array( 48 48 $this->getQueryRoutePattern() => 'NuanceSourceListController', 49 + $this->getEditRoutePattern('edit/') => 'NuanceSourceEditController', 49 50 'view/(?P<id>[1-9]\d*)/' => 'NuanceSourceViewController', 50 - 'edit/(?P<id>[1-9]\d*)/' => 'NuanceSourceEditController', 51 - 'new/(?P<type>[^/]+)/' => 'NuanceSourceEditController', 52 - 'create/' => 'NuanceSourceCreateController', 53 51 ), 54 52 'queue/' => array( 55 53 $this->getQueryRoutePattern() => 'NuanceQueueListController', 56 54 $this->getEditRoutePattern('edit/') => 'NuanceQueueEditController', 57 55 'view/(?P<id>[1-9]\d*)/' => 'NuanceQueueViewController', 58 - 'new/' => 'NuanceQueueEditController', 59 56 ), 60 57 'requestor/' => array( 61 58 'view/(?P<id>[1-9]\d*)/' => 'NuanceRequestorViewController',
+1 -1
src/applications/nuance/controller/NuanceItemViewController.php
··· 49 49 phabricator_datetime($item->getDateCreated(), $viewer)); 50 50 51 51 $source = $item->getSource(); 52 - $definition = $source->requireDefinition(); 52 + $definition = $source->getDefinition(); 53 53 54 54 $definition->renderItemViewProperties( 55 55 $viewer,
+3 -10
src/applications/nuance/controller/NuanceQueueListController.php
··· 12 12 protected function buildApplicationCrumbs() { 13 13 $crumbs = parent::buildApplicationCrumbs(); 14 14 15 - // TODO: Maybe use SourceManage capability? 16 - $can_create = true; 17 - 18 - $crumbs->addAction( 19 - id(new PHUIListItemView()) 20 - ->setName(pht('Create Queue')) 21 - ->setHref($this->getApplicationURI('queue/new/')) 22 - ->setIcon('fa-plus-square') 23 - ->setDisabled(!$can_create) 24 - ->setWorkflow(!$can_create)); 15 + id(new NuanceQueueEditEngine()) 16 + ->setViewer($this->getViewer()) 17 + ->addActionToCrumbs($crumbs); 25 18 26 19 return $crumbs; 27 20 }
+9 -10
src/applications/nuance/controller/NuanceSourceActionController.php
··· 13 13 return new Aphront404Response(); 14 14 } 15 15 16 - $def = $source->requireDefinition(); 17 - $def->setActor($viewer); 16 + $def = $source->getDefinition(); 17 + 18 + $def 19 + ->setViewer($viewer) 20 + ->setSource($source); 18 21 19 22 $response = $def->handleActionRequest($request); 20 23 if ($response instanceof AphrontResponse) { ··· 25 28 $crumbs = $this->buildApplicationCrumbs(); 26 29 $crumbs->addTextCrumb($title); 27 30 28 - return $this->buildApplicationPage( 29 - array( 30 - $crumbs, 31 - $response, 32 - ), 33 - array( 34 - 'title' => $title, 35 - )); 31 + return $this->newPage() 32 + ->setTitle($title) 33 + ->setCrumbs($crumbs) 34 + ->appendChild($response); 36 35 } 37 36 38 37 }
-58
src/applications/nuance/controller/NuanceSourceCreateController.php
··· 1 - <?php 2 - 3 - final class NuanceSourceCreateController 4 - extends NuanceSourceController { 5 - 6 - public function handleRequest(AphrontRequest $request) { 7 - $can_edit = $this->requireApplicationCapability( 8 - NuanceSourceManageCapability::CAPABILITY); 9 - 10 - $viewer = $this->getViewer(); 11 - $map = NuanceSourceDefinition::getAllDefinitions(); 12 - $cancel_uri = $this->getApplicationURI('source/'); 13 - 14 - if ($request->isFormPost()) { 15 - $type = $request->getStr('type'); 16 - if (isset($map[$type])) { 17 - $uri = $this->getApplicationURI('source/new/'.$type.'/'); 18 - return id(new AphrontRedirectResponse())->setURI($uri); 19 - } 20 - } 21 - 22 - $source_types = id(new AphrontFormRadioButtonControl()) 23 - ->setName('type') 24 - ->setLabel(pht('Source Type')); 25 - 26 - foreach ($map as $type => $definition) { 27 - $source_types->addButton( 28 - $type, 29 - $definition->getName(), 30 - $definition->getSourceDescription()); 31 - } 32 - 33 - $form = id(new AphrontFormView()) 34 - ->setUser($viewer) 35 - ->appendChild($source_types) 36 - ->appendChild( 37 - id(new AphrontFormSubmitControl()) 38 - ->setValue(pht('Continue')) 39 - ->addCancelButton($cancel_uri)); 40 - 41 - $box = id(new PHUIObjectBoxView()) 42 - ->setHeaderText(pht('Choose Source Type')) 43 - ->appendChild($form); 44 - 45 - $crumbs = $this->buildApplicationCrumbs(); 46 - $crumbs->addTextCrumb(pht('Sources'), $cancel_uri); 47 - $crumbs->addTextCrumb(pht('New')); 48 - 49 - return $this->buildApplicationPage( 50 - array( 51 - $crumbs, 52 - $box, 53 - ), 54 - array( 55 - 'title' => pht('Choose Source Type'), 56 - )); 57 - } 58 - }
+55 -52
src/applications/nuance/controller/NuanceSourceEditController.php
··· 4 4 extends NuanceSourceController { 5 5 6 6 public function handleRequest(AphrontRequest $request) { 7 - $can_edit = $this->requireApplicationCapability( 8 - NuanceSourceManageCapability::CAPABILITY); 7 + $engine = id(new NuanceSourceEditEngine()) 8 + ->setController($this); 9 9 10 - $viewer = $this->getViewer(); 10 + $id = $request->getURIData('id'); 11 + if (!$id) { 12 + $this->requireApplicationCapability( 13 + NuanceSourceManageCapability::CAPABILITY); 11 14 12 - $sources_uri = $this->getApplicationURI('source/'); 15 + $cancel_uri = $this->getApplicationURI('source/'); 16 + $map = NuanceSourceDefinition::getAllDefinitions(); 17 + $source_type = $request->getStr('sourceType'); 18 + if (!isset($map[$source_type])) { 19 + return $this->buildSourceTypeResponse($cancel_uri); 20 + } 13 21 14 - $source_id = $request->getURIData('id'); 15 - $is_new = !$source_id; 22 + $engine 23 + ->setSourceDefinition($map[$source_type]) 24 + ->addContextParameter('sourceType', $source_type); 25 + } 16 26 17 - if ($is_new) { 18 - $source = NuanceSource::initializeNewSource($viewer); 27 + return $engine->buildResponse(); 28 + } 19 29 20 - $type = $request->getURIData('type'); 21 - $map = NuanceSourceDefinition::getAllDefinitions(); 30 + private function buildSourceTypeResponse($cancel_uri) { 31 + $viewer = $this->getViewer(); 32 + $request = $this->getRequest(); 33 + $map = NuanceSourceDefinition::getAllDefinitions(); 22 34 23 - if (empty($map[$type])) { 24 - return new Aphront404Response(); 25 - } 35 + $errors = array(); 36 + $e_source = null; 37 + if ($request->isFormPost()) { 38 + $errors[] = pht('You must choose a source type.'); 39 + $e_source = pht('Required'); 40 + } 41 + 42 + $source_types = id(new AphrontFormRadioButtonControl()) 43 + ->setName('sourceType') 44 + ->setLabel(pht('Source Type')); 26 45 27 - $source->setType($type); 28 - $cancel_uri = $sources_uri; 29 - } else { 30 - $source = id(new NuanceSourceQuery()) 31 - ->setViewer($viewer) 32 - ->withIDs(array($source_id)) 33 - ->requireCapabilities( 34 - array( 35 - PhabricatorPolicyCapability::CAN_VIEW, 36 - PhabricatorPolicyCapability::CAN_EDIT, 37 - )) 38 - ->executeOne(); 39 - if (!$source) { 40 - return new Aphront404Response(); 41 - } 42 - $cancel_uri = $source->getURI(); 46 + foreach ($map as $type => $definition) { 47 + $source_types->addButton( 48 + $type, 49 + $definition->getName(), 50 + $definition->getSourceDescription()); 43 51 } 44 52 45 - $definition = $source->requireDefinition(); 46 - $definition->setActor($viewer); 53 + $form = id(new AphrontFormView()) 54 + ->setUser($viewer) 55 + ->appendChild($source_types) 56 + ->appendChild( 57 + id(new AphrontFormSubmitControl()) 58 + ->setValue(pht('Continue')) 59 + ->addCancelButton($cancel_uri)); 47 60 48 - $response = $definition->buildEditLayout($request); 49 - if ($response instanceof AphrontResponse) { 50 - return $response; 51 - } 52 - $layout = $response; 61 + $box = id(new PHUIObjectBoxView()) 62 + ->setFormErrors($errors) 63 + ->setHeaderText(pht('Choose Source Type')) 64 + ->appendChild($form); 53 65 54 66 $crumbs = $this->buildApplicationCrumbs(); 55 - $crumbs->addTextCrumb(pht('Sources'), $sources_uri); 56 - 57 - if ($is_new) { 58 - $crumbs->addTextCrumb(pht('New')); 59 - } else { 60 - $crumbs->addTextCrumb($source->getName(), $cancel_uri); 61 - $crumbs->addTextCrumb(pht('Edit')); 62 - } 67 + $crumbs->addTextCrumb(pht('Sources'), $cancel_uri); 68 + $crumbs->addTextCrumb(pht('New')); 63 69 64 - return $this->buildApplicationPage( 65 - array( 66 - $crumbs, 67 - $layout, 68 - ), 69 - array( 70 - 'title' => $definition->getEditTitle(), 71 - )); 70 + return $this->newPage() 71 + ->setTitle(pht('Choose Source Type')) 72 + ->setCrumbs($crumbs) 73 + ->appendChild($box); 72 74 } 75 + 73 76 }
+3 -10
src/applications/nuance/controller/NuanceSourceListController.php
··· 12 12 protected function buildApplicationCrumbs() { 13 13 $crumbs = parent::buildApplicationCrumbs(); 14 14 15 - $can_create = $this->hasApplicationCapability( 16 - NuanceSourceManageCapability::CAPABILITY); 17 - 18 - $crumbs->addAction( 19 - id(new PHUIListItemView()) 20 - ->setName(pht('Create Source')) 21 - ->setHref($this->getApplicationURI('source/create/')) 22 - ->setIcon('fa-plus-square') 23 - ->setDisabled(!$can_create) 24 - ->setWorkflow(!$can_create)); 15 + id(new NuanceSourceEditEngine()) 16 + ->setViewer($this->getViewer()) 17 + ->addActionToCrumbs($crumbs); 25 18 26 19 return $crumbs; 27 20 }
+8 -2
src/applications/nuance/controller/NuanceSourceViewController.php
··· 84 84 ->setWorkflow(!$can_edit)); 85 85 86 86 $request = $this->getRequest(); 87 - $definition = $source->requireDefinition(); 87 + $definition = $source->getDefinition(); 88 + 89 + $definition 90 + ->setViewer($viewer) 91 + ->setSource($source); 92 + 88 93 $source_actions = $definition->getSourceViewActions($request); 89 94 foreach ($source_actions as $source_action) { 90 95 $curtain->addAction($source_action); ··· 100 105 $properties = id(new PHUIPropertyListView()) 101 106 ->setViewer($viewer); 102 107 103 - $definition = $source->requireDefinition(); 108 + $definition = $source->getDefinition(); 109 + 104 110 $properties->addProperty( 105 111 pht('Source Type'), 106 112 $definition->getName());
+108
src/applications/nuance/editor/NuanceSourceEditEngine.php
··· 1 + <?php 2 + 3 + final class NuanceSourceEditEngine 4 + extends PhabricatorEditEngine { 5 + 6 + const ENGINECONST = 'nuance.source'; 7 + 8 + private $sourceDefinition; 9 + 10 + public function setSourceDefinition( 11 + NuanceSourceDefinition $source_definition) { 12 + $this->sourceDefinition = $source_definition; 13 + return $this; 14 + } 15 + 16 + public function getSourceDefinition() { 17 + return $this->sourceDefinition; 18 + } 19 + 20 + public function isEngineConfigurable() { 21 + return false; 22 + } 23 + 24 + public function getEngineName() { 25 + return pht('Nuance Sources'); 26 + } 27 + 28 + public function getSummaryHeader() { 29 + return pht('Edit Nuance Source Configurations'); 30 + } 31 + 32 + public function getSummaryText() { 33 + return pht('This engine is used to edit Nuance sources.'); 34 + } 35 + 36 + public function getEngineApplicationClass() { 37 + return 'PhabricatorNuanceApplication'; 38 + } 39 + 40 + protected function newEditableObject() { 41 + $viewer = $this->getViewer(); 42 + 43 + $definition = $this->getSourceDefinition(); 44 + if (!$definition) { 45 + throw new PhutilInvalidStateException('setSourceDefinition'); 46 + } 47 + 48 + return NuanceSource::initializeNewSource( 49 + $viewer, 50 + $definition); 51 + } 52 + 53 + protected function newObjectQuery() { 54 + return new NuanceSourceQuery(); 55 + } 56 + 57 + protected function getObjectCreateTitleText($object) { 58 + return pht('Create Source'); 59 + } 60 + 61 + protected function getObjectCreateButtonText($object) { 62 + return pht('Create Source'); 63 + } 64 + 65 + protected function getObjectEditTitleText($object) { 66 + return pht('Edit Source: %s', $object->getName()); 67 + } 68 + 69 + protected function getObjectEditShortText($object) { 70 + return pht('Edit Source'); 71 + } 72 + 73 + protected function getObjectCreateShortText() { 74 + return pht('Create Source'); 75 + } 76 + 77 + protected function getEditorURI() { 78 + return '/nuance/source/edit/'; 79 + } 80 + 81 + protected function getObjectCreateCancelURI($object) { 82 + return '/nuance/source/'; 83 + } 84 + 85 + protected function getObjectViewURI($object) { 86 + return $object->getURI(); 87 + } 88 + 89 + protected function buildCustomEditFields($object) { 90 + return array( 91 + id(new PhabricatorTextEditField()) 92 + ->setKey('name') 93 + ->setLabel(pht('Name')) 94 + ->setDescription(pht('Name of the source.')) 95 + ->setTransactionType(NuanceSourceTransaction::TYPE_NAME) 96 + ->setIsRequired(true) 97 + ->setValue($object->getName()), 98 + id(new PhabricatorDatasourceEditField()) 99 + ->setKey('defaultQueue') 100 + ->setLabel(pht('Default Queue')) 101 + ->setDescription(pht('Default queue.')) 102 + ->setTransactionType(NuanceSourceTransaction::TYPE_DEFAULT_QUEUE) 103 + ->setDatasource(new NuanceQueueDatasource()) 104 + ->setSingleValue($object->getDefaultQueuePHID()), 105 + ); 106 + } 107 + 108 + }
+17
src/applications/nuance/query/NuanceSourceQuery.php
··· 30 30 return $this->loadStandardPage($this->newResultObject()); 31 31 } 32 32 33 + protected function willFilterPage(array $sources) { 34 + $all_types = NuanceSourceDefinition::getAllDefinitions(); 35 + 36 + foreach ($sources as $key => $source) { 37 + $definition = idx($all_types, $source->getType()); 38 + if (!$definition) { 39 + $this->didRejectResult($source); 40 + unset($sources[$key]); 41 + continue; 42 + } 43 + $source->attachDefinition($definition); 44 + } 45 + 46 + return $sources; 47 + } 48 + 49 + 33 50 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 34 51 $where = parent::buildWhereClauseParts($conn); 35 52
-19
src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
··· 30 30 return null; 31 31 } 32 32 33 - protected function augmentEditForm( 34 - AphrontFormView $form, 35 - PhabricatorApplicationTransactionValidationException $ex = null) { 36 - 37 - /* TODO - add a box to allow for custom fields to be defined here, so that 38 - * these NuanceSource objects made from this definition can be used to 39 - * capture arbitrary data */ 40 - 41 - return $form; 42 - } 43 - 44 - protected function buildTransactions(AphrontRequest $request) { 45 - $transactions = parent::buildTransactions($request); 46 - 47 - // TODO -- as above 48 - 49 - return $transactions; 50 - } 51 - 52 33 public function renderView() {} 53 34 54 35 public function renderListView() {}
+16 -187
src/applications/nuance/source/NuanceSourceDefinition.php
··· 5 5 */ 6 6 abstract class NuanceSourceDefinition extends Phobject { 7 7 8 - private $actor; 9 - private $sourceObject; 8 + private $viewer; 9 + private $source; 10 10 11 - public function setActor(PhabricatorUser $actor) { 12 - $this->actor = $actor; 11 + public function setViewer(PhabricatorUser $viewer) { 12 + $this->viewer = $viewer; 13 13 return $this; 14 14 } 15 15 16 - public function getActor() { 17 - return $this->actor; 18 - } 19 - 20 - public function requireActor() { 21 - $actor = $this->getActor(); 22 - if (!$actor) { 23 - throw new PhutilInvalidStateException('setActor'); 16 + public function getViewer() { 17 + if (!$this->viewer) { 18 + throw new PhutilInvalidStateException('setViewer'); 24 19 } 25 - return $actor; 20 + return $this->viewer; 26 21 } 27 22 28 - public function setSourceObject(NuanceSource $source) { 29 - $source->setType($this->getSourceTypeConstant()); 30 - $this->sourceObject = $source; 23 + public function setSource(NuanceSource $source) { 24 + $this->source = $source; 31 25 return $this; 32 26 } 33 27 34 - public function getSourceObject() { 35 - return $this->sourceObject; 36 - } 37 - 38 - public function requireSourceObject() { 39 - $source = $this->getSourceObject(); 40 - if (!$source) { 41 - throw new PhutilInvalidStateException('setSourceObject'); 28 + public function getSource() { 29 + if (!$this->source) { 30 + throw new PhutilInvalidStateException('setSource'); 42 31 } 43 - return $source; 32 + return $this->source; 44 33 } 45 34 46 35 public function getSourceViewActions(AphrontRequest $request) { ··· 84 73 */ 85 74 abstract public function updateItems(); 86 75 87 - private function loadSourceObjectPolicies( 88 - PhabricatorUser $user, 89 - NuanceSource $source) { 90 - 91 - $user = $this->requireActor(); 92 - $source = $this->requireSourceObject(); 93 - return id(new PhabricatorPolicyQuery()) 94 - ->setViewer($user) 95 - ->setObject($source) 96 - ->execute(); 97 - } 98 - 99 - final public function getEditTitle() { 100 - $source = $this->requireSourceObject(); 101 - if ($source->getPHID()) { 102 - $title = pht('Edit "%s" source.', $source->getName()); 103 - } else { 104 - $title = pht('Create a new "%s" source.', $this->getName()); 105 - } 106 - 107 - return $title; 108 - } 109 - 110 - final public function buildEditLayout(AphrontRequest $request) { 111 - $actor = $this->requireActor(); 112 - $source = $this->requireSourceObject(); 113 - 114 - $form_errors = array(); 115 - $error_messages = array(); 116 - $transactions = array(); 117 - $validation_exception = null; 118 - if ($request->isFormPost()) { 119 - $transactions = $this->buildTransactions($request); 120 - try { 121 - $editor = id(new NuanceSourceEditor()) 122 - ->setActor($actor) 123 - ->setContentSourceFromRequest($request) 124 - ->setContinueOnNoEffect(true) 125 - ->applyTransactions($source, $transactions); 126 - 127 - return id(new AphrontRedirectResponse()) 128 - ->setURI($source->getURI()); 129 - 130 - } catch (PhabricatorApplicationTransactionValidationException $ex) { 131 - $validation_exception = $ex; 132 - } 133 - 134 - } 135 - 136 - $form = $this->renderEditForm($validation_exception); 137 - $layout = id(new PHUIObjectBoxView()) 138 - ->setHeaderText($this->getEditTitle()) 139 - ->setValidationException($validation_exception) 140 - ->setFormErrors($error_messages) 141 - ->setForm($form); 142 - 143 - return $layout; 144 - } 145 - 146 - /** 147 - * Code to create a form to edit the @{class:NuanceItem} you are defining. 148 - * 149 - * return @{class:AphrontFormView} 150 - */ 151 - private function renderEditForm( 152 - PhabricatorApplicationTransactionValidationException $ex = null) { 153 - $user = $this->requireActor(); 154 - $source = $this->requireSourceObject(); 155 - $policies = $this->loadSourceObjectPolicies($user, $source); 156 - $e_name = null; 157 - if ($ex) { 158 - $e_name = $ex->getShortMessage(NuanceSourceTransaction::TYPE_NAME); 159 - } 160 - 161 - $form = id(new AphrontFormView()) 162 - ->setUser($user) 163 - ->appendChild( 164 - id(new AphrontFormTextControl()) 165 - ->setLabel(pht('Name')) 166 - ->setName('name') 167 - ->setError($e_name) 168 - ->setValue($source->getName())); 169 - 170 - $form = $this->augmentEditForm($form, $ex); 171 - 172 - $default_phid = $source->getDefaultQueuePHID(); 173 - if ($default_phid) { 174 - $default_queues = array($default_phid); 175 - } else { 176 - $default_queues = array(); 177 - } 178 - 179 - $form 180 - ->appendControl( 181 - id(new AphrontFormTokenizerControl()) 182 - ->setLabel(pht('Default Queue')) 183 - ->setName('defaultQueuePHIDs') 184 - ->setLimit(1) 185 - ->setDatasource(new NuanceQueueDatasource()) 186 - ->setValue($default_queues)) 187 - ->appendChild( 188 - id(new AphrontFormPolicyControl()) 189 - ->setUser($user) 190 - ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) 191 - ->setPolicyObject($source) 192 - ->setPolicies($policies) 193 - ->setName('viewPolicy')) 194 - ->appendChild( 195 - id(new AphrontFormPolicyControl()) 196 - ->setUser($user) 197 - ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) 198 - ->setPolicyObject($source) 199 - ->setPolicies($policies) 200 - ->setName('editPolicy')) 201 - ->appendChild( 202 - id(new AphrontFormSubmitControl()) 203 - ->addCancelButton($source->getURI()) 204 - ->setValue(pht('Save'))); 205 - 206 - return $form; 207 - } 208 - 209 - /** 210 - * return @{class:AphrontFormView} 211 - */ 212 - protected function augmentEditForm( 213 - AphrontFormView $form, 214 - PhabricatorApplicationTransactionValidationException $ex = null) { 215 - 216 - return $form; 217 - } 218 - 219 - /** 220 - * Hook to build up @{class:PhabricatorTransactions}. 221 - * 222 - * return array $transactions 223 - */ 224 - protected function buildTransactions(AphrontRequest $request) { 225 - $transactions = array(); 226 - 227 - $transactions[] = id(new NuanceSourceTransaction()) 228 - ->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY) 229 - ->setNewValue($request->getStr('editPolicy')); 230 - 231 - $transactions[] = id(new NuanceSourceTransaction()) 232 - ->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY) 233 - ->setNewValue($request->getStr('viewPolicy')); 234 - 235 - $transactions[] = id(new NuanceSourceTransaction()) 236 - ->setTransactionType(NuanceSourceTransaction::TYPE_NAME) 237 - ->setNewvalue($request->getStr('name')); 238 - 239 - $transactions[] = id(new NuanceSourceTransaction()) 240 - ->setTransactionType(NuanceSourceTransaction::TYPE_DEFAULT_QUEUE) 241 - ->setNewvalue(head($request->getArr('defaultQueuePHIDs'))); 242 - 243 - return $transactions; 244 - } 245 - 246 76 abstract public function renderView(); 247 77 248 78 abstract public function renderListView(); ··· 256 86 // TODO: Should we have a tighter actor/viewer model? Requestors will 257 87 // often have no real user associated with them... 258 88 $actor = PhabricatorUser::getOmnipotentUser(); 259 - 260 - $source = $this->requireSourceObject(); 89 + $source = $this->getSource(); 261 90 262 91 $item = NuanceItem::initializeNewItem(); 263 92 ··· 317 146 } 318 147 319 148 public function getActionURI($path = null) { 320 - $source_id = $this->getSourceObject()->getID(); 149 + $source_id = $this->getSource()->getID(); 321 150 return '/action/'.$source_id.'/'.ltrim($path, '/'); 322 151 } 323 152
+11 -23
src/applications/nuance/storage/NuanceSource.php
··· 13 13 protected $editPolicy; 14 14 protected $defaultQueuePHID; 15 15 16 - private $definition; 16 + private $definition = self::ATTACHABLE; 17 17 18 18 protected function getConfiguration() { 19 19 return array( ··· 49 49 return '/nuance/source/view/'.$this->getID().'/'; 50 50 } 51 51 52 - public static function initializeNewSource(PhabricatorUser $actor) { 52 + public static function initializeNewSource( 53 + PhabricatorUser $actor, 54 + NuanceSourceDefinition $definition) { 53 55 $app = id(new PhabricatorApplicationQuery()) 54 56 ->setViewer($actor) 55 57 ->withClasses(array('PhabricatorNuanceApplication')) ··· 62 64 63 65 return id(new NuanceSource()) 64 66 ->setViewPolicy($view_policy) 65 - ->setEditPolicy($edit_policy); 67 + ->setEditPolicy($edit_policy) 68 + ->setType($definition->getSourceTypeConstant()) 69 + ->attachDefinition($definition); 66 70 } 67 71 68 72 public function getDefinition() { 69 - if ($this->definition === null) { 70 - $definitions = NuanceSourceDefinition::getAllDefinitions(); 71 - if (isset($definitions[$this->getType()])) { 72 - $definition = clone $definitions[$this->getType()]; 73 - $definition->setSourceObject($this); 74 - $this->definition = $definition; 75 - } 76 - } 77 - 78 - return $this->definition; 73 + return $this->assertAttached($this->definition); 79 74 } 80 75 81 - public function requireDefinition() { 82 - $definition = $this->getDefinition(); 83 - if (!$definition) { 84 - throw new Exception( 85 - pht( 86 - 'Unable to load source definition implementation for source '. 87 - 'type "%s".', 88 - $this->getType())); 89 - } 90 - return $definition; 76 + public function attachDefinition(NuanceSourceDefinition $definition) { 77 + $this->definition = $definition; 78 + return $this; 91 79 } 92 80 93 81