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

Allow Nuance source definitions to add actions to source views

Summary:
Ref T8783. If you have a source (like a "report bug" form), let it put a link (like "View Form") on the source detail page.

This also straightens out getting definitions from sources, which had a bug with the modern way we do `PhutilClassMapQuery`.

Specifically, if you called the old mechanism on two different sources, they'd return the same definition object, but they need to return different definitions.

Test Plan:
{F747093}

{F747092}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T8783

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

+55 -15
+1 -1
src/applications/nuance/controller/NuanceSourceActionController.php
··· 13 13 return new Aphront404Response(); 14 14 } 15 15 16 - $def = NuanceSourceDefinition::getDefinitionForSource($source); 16 + $def = $source->requireDefinition(); 17 17 $def->setActor($viewer); 18 18 19 19 $response = $def->handleActionRequest($request);
+1 -1
src/applications/nuance/controller/NuanceSourceEditController.php
··· 41 41 $cancel_uri = $source->getURI(); 42 42 } 43 43 44 - $definition = NuanceSourceDefinition::getDefinitionForSource($source); 44 + $definition = $source->requireDefinition(); 45 45 $definition->setActor($viewer); 46 46 47 47 $response = $definition->buildEditLayout($request);
+8 -1
src/applications/nuance/controller/NuanceSourceViewController.php
··· 77 77 ->setDisabled(!$can_edit) 78 78 ->setWorkflow(!$can_edit)); 79 79 80 + $request = $this->getRequest(); 81 + $definition = $source->requireDefinition(); 82 + $source_actions = $definition->getSourceViewActions($request); 83 + foreach ($source_actions as $source_action) { 84 + $actions->addAction($source_action); 85 + } 86 + 80 87 return $actions; 81 88 } 82 89 ··· 90 97 ->setObject($source) 91 98 ->setActionList($actions); 92 99 93 - $definition = NuanceSourceDefinition::getDefinitionForSource($source); 100 + $definition = $source->requireDefinition(); 94 101 $properties->addProperty( 95 102 pht('Source Type'), 96 103 $definition->getName());
+11
src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
··· 15 15 return 'phabricator-form'; 16 16 } 17 17 18 + public function getSourceViewActions(AphrontRequest $request) { 19 + $actions = array(); 20 + 21 + $actions[] = id(new PhabricatorActionView()) 22 + ->setName(pht('View Form')) 23 + ->setIcon('fa-align-justify') 24 + ->setHref($this->getActionURI()); 25 + 26 + return $actions; 27 + } 28 + 18 29 public function updateItems() { 19 30 return null; 20 31 }
+7 -12
src/applications/nuance/source/NuanceSourceDefinition.php
··· 43 43 return $source; 44 44 } 45 45 46 - /** 47 - * Gives a @{class:NuanceSourceDefinition} object for a given 48 - * @{class:NuanceSource}. Note you still need to @{method:setActor} 49 - * before the @{class:NuanceSourceDefinition} object will be useful. 50 - */ 51 - public static function getDefinitionForSource(NuanceSource $source) { 52 - $definitions = self::getAllDefinitions(); 53 - $map = mpull($definitions, null, 'getSourceTypeConstant'); 54 - $definition = $map[$source->getType()]; 55 - $definition->setSourceObject($source); 56 - 57 - return $definition; 46 + public function getSourceViewActions(AphrontRequest $request) { 47 + return array(); 58 48 } 59 49 60 50 public static function getAllDefinitions() { ··· 284 274 285 275 public function handleActionRequest(AphrontRequest $request) { 286 276 return new Aphront404Response(); 277 + } 278 + 279 + public function getActionURI($path = null) { 280 + $source_id = $this->getSourceObject()->getID(); 281 + return '/action/'.$source_id.'/'.ltrim($path, '/'); 287 282 } 288 283 289 284 }
+27
src/applications/nuance/storage/NuanceSource.php
··· 12 12 protected $viewPolicy; 13 13 protected $editPolicy; 14 14 15 + private $definition; 16 + 15 17 protected function getConfiguration() { 16 18 return array( 17 19 self::CONFIG_AUX_PHID => true, ··· 60 62 return id(new NuanceSource()) 61 63 ->setViewPolicy($view_policy) 62 64 ->setEditPolicy($edit_policy); 65 + } 66 + 67 + public function getDefinition() { 68 + if ($this->definition === null) { 69 + $definitions = NuanceSourceDefinition::getAllDefinitions(); 70 + if (isset($definitions[$this->getType()])) { 71 + $definition = clone $definitions[$this->getType()]; 72 + $definition->setSourceObject($this); 73 + $this->definition = $definition; 74 + } 75 + } 76 + 77 + return $this->definition; 78 + } 79 + 80 + public function requireDefinition() { 81 + $definition = $this->getDefinition(); 82 + if (!$definition) { 83 + throw new Exception( 84 + pht( 85 + 'Unable to load source definition implementation for source '. 86 + 'type "%s".', 87 + $this->getType())); 88 + } 89 + return $definition; 63 90 } 64 91 65 92