Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15422110
D13966.id33702.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D13966.id33702.diff
View Options
diff --git a/src/applications/nuance/controller/NuanceSourceActionController.php b/src/applications/nuance/controller/NuanceSourceActionController.php
--- a/src/applications/nuance/controller/NuanceSourceActionController.php
+++ b/src/applications/nuance/controller/NuanceSourceActionController.php
@@ -13,7 +13,7 @@
return new Aphront404Response();
}
- $def = NuanceSourceDefinition::getDefinitionForSource($source);
+ $def = $source->requireDefinition();
$def->setActor($viewer);
$response = $def->handleActionRequest($request);
diff --git a/src/applications/nuance/controller/NuanceSourceEditController.php b/src/applications/nuance/controller/NuanceSourceEditController.php
--- a/src/applications/nuance/controller/NuanceSourceEditController.php
+++ b/src/applications/nuance/controller/NuanceSourceEditController.php
@@ -41,7 +41,7 @@
$cancel_uri = $source->getURI();
}
- $definition = NuanceSourceDefinition::getDefinitionForSource($source);
+ $definition = $source->requireDefinition();
$definition->setActor($viewer);
$response = $definition->buildEditLayout($request);
diff --git a/src/applications/nuance/controller/NuanceSourceViewController.php b/src/applications/nuance/controller/NuanceSourceViewController.php
--- a/src/applications/nuance/controller/NuanceSourceViewController.php
+++ b/src/applications/nuance/controller/NuanceSourceViewController.php
@@ -77,6 +77,13 @@
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
+ $request = $this->getRequest();
+ $definition = $source->requireDefinition();
+ $source_actions = $definition->getSourceViewActions($request);
+ foreach ($source_actions as $source_action) {
+ $actions->addAction($source_action);
+ }
+
return $actions;
}
@@ -90,7 +97,7 @@
->setObject($source)
->setActionList($actions);
- $definition = NuanceSourceDefinition::getDefinitionForSource($source);
+ $definition = $source->requireDefinition();
$properties->addProperty(
pht('Source Type'),
$definition->getName());
diff --git a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
--- a/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
+++ b/src/applications/nuance/source/NuancePhabricatorFormSourceDefinition.php
@@ -15,6 +15,17 @@
return 'phabricator-form';
}
+ public function getSourceViewActions(AphrontRequest $request) {
+ $actions = array();
+
+ $actions[] = id(new PhabricatorActionView())
+ ->setName(pht('View Form'))
+ ->setIcon('fa-align-justify')
+ ->setHref($this->getActionURI());
+
+ return $actions;
+ }
+
public function updateItems() {
return null;
}
diff --git a/src/applications/nuance/source/NuanceSourceDefinition.php b/src/applications/nuance/source/NuanceSourceDefinition.php
--- a/src/applications/nuance/source/NuanceSourceDefinition.php
+++ b/src/applications/nuance/source/NuanceSourceDefinition.php
@@ -43,18 +43,8 @@
return $source;
}
- /**
- * Gives a @{class:NuanceSourceDefinition} object for a given
- * @{class:NuanceSource}. Note you still need to @{method:setActor}
- * before the @{class:NuanceSourceDefinition} object will be useful.
- */
- public static function getDefinitionForSource(NuanceSource $source) {
- $definitions = self::getAllDefinitions();
- $map = mpull($definitions, null, 'getSourceTypeConstant');
- $definition = $map[$source->getType()];
- $definition->setSourceObject($source);
-
- return $definition;
+ public function getSourceViewActions(AphrontRequest $request) {
+ return array();
}
public static function getAllDefinitions() {
@@ -286,4 +276,9 @@
return new Aphront404Response();
}
+ public function getActionURI($path = null) {
+ $source_id = $this->getSourceObject()->getID();
+ return '/action/'.$source_id.'/'.ltrim($path, '/');
+ }
+
}
diff --git a/src/applications/nuance/storage/NuanceSource.php b/src/applications/nuance/storage/NuanceSource.php
--- a/src/applications/nuance/storage/NuanceSource.php
+++ b/src/applications/nuance/storage/NuanceSource.php
@@ -12,6 +12,8 @@
protected $viewPolicy;
protected $editPolicy;
+ private $definition;
+
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
@@ -62,6 +64,31 @@
->setEditPolicy($edit_policy);
}
+ public function getDefinition() {
+ if ($this->definition === null) {
+ $definitions = NuanceSourceDefinition::getAllDefinitions();
+ if (isset($definitions[$this->getType()])) {
+ $definition = clone $definitions[$this->getType()];
+ $definition->setSourceObject($this);
+ $this->definition = $definition;
+ }
+ }
+
+ return $this->definition;
+ }
+
+ public function requireDefinition() {
+ $definition = $this->getDefinition();
+ if (!$definition) {
+ throw new Exception(
+ pht(
+ 'Unable to load source definition implementation for source '.
+ 'type "%s".',
+ $this->getType()));
+ }
+ return $definition;
+ }
+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 23, 5:34 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7592156
Default Alt Text
D13966.id33702.diff (5 KB)
Attached To
Mode
D13966: Allow Nuance source definitions to add actions to source views
Attached
Detach File
Event Timeline
Log In to Comment