From 30d6cd91daa36ff18d9e74b965d44ed7e9314f4b Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 7 Mar 2013 17:24:33 -0800 Subject: [PATCH] Implement remarkup custom control Summary: Ref T2575. Adds "remarkup" control, which displays a remarkup control and uses the remarkup cache. Grants fields access to remarkup pipeline. Test Plan: {F35067} {F35068} Used DarkConsole to verify cache interaction with services. Reviewers: hach-que, btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2575 Differential Revision: https://secure.phabricator.com/D5286 --- src/__phutil_library_map__.php | 1 + ...hestAuxiliaryFieldDefaultSpecification.php | 37 +++++++++---- .../ManiphestAuxiliaryFieldSpecification.php | 52 ++++++++++++++++++- .../ManiphestTaskDetailController.php | 10 +++- src/docs/userguide/maniphest_custom.diviner | 4 +- 5 files changed, 91 insertions(+), 13 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 58aa47b251..6754ebd8cd 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2084,6 +2084,7 @@ phutil_register_library_map(array( 'LiskMigrationIterator' => 'PhutilBufferedIterator', 'ManiphestAction' => 'ManiphestConstants', 'ManiphestAuxiliaryFieldDefaultSpecification' => 'ManiphestAuxiliaryFieldSpecification', + 'ManiphestAuxiliaryFieldSpecification' => 'PhabricatorMarkupInterface', 'ManiphestAuxiliaryFieldTypeException' => 'Exception', 'ManiphestAuxiliaryFieldValidationException' => 'Exception', 'ManiphestBatchEditController' => 'ManiphestController', diff --git a/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php b/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php index 032a9b00a4..b0818a22e6 100644 --- a/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php +++ b/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldDefaultSpecification.php @@ -15,11 +15,12 @@ class ManiphestAuxiliaryFieldDefaultSpecification private $error; private $shouldCopyWhenCreatingSimilarTask; - const TYPE_SELECT = 'select'; - const TYPE_STRING = 'string'; - const TYPE_INT = 'int'; - const TYPE_BOOL = 'bool'; - const TYPE_DATE = 'date'; + const TYPE_SELECT = 'select'; + const TYPE_STRING = 'string'; + const TYPE_INT = 'int'; + const TYPE_BOOL = 'bool'; + const TYPE_DATE = 'date'; + const TYPE_REMARKUP = 'remarkup'; public function getFieldType() { return $this->fieldType; @@ -97,6 +98,10 @@ class ManiphestAuxiliaryFieldDefaultSpecification $control = new AphrontFormDateControl(); $control->setUser($this->getUser()); break; + case self::TYPE_REMARKUP: + $control = new PhabricatorRemarkupControl(); + $control->setUser($this->getUser()); + break; default: $label = $this->getLabel(); throw new ManiphestAuxiliaryFieldTypeException( @@ -193,6 +198,14 @@ class ManiphestAuxiliaryFieldDefaultSpecification } } + public function getMarkupFields() { + switch ($this->getFieldType()) { + case self::TYPE_REMARKUP: + return array('default'); + } + return parent::getMarkupFields(); + } + public function renderForDetailView() { switch ($this->getFieldType()) { case self::TYPE_BOOL: @@ -202,11 +215,13 @@ class ManiphestAuxiliaryFieldDefaultSpecification return null; } case self::TYPE_SELECT: - $display = idx($this->getSelectOptions(), $this->getValue()); - return $display; + return idx($this->getSelectOptions(), $this->getValue()); case self::TYPE_DATE: - $display = phabricator_datetime($this->getValue(), $this->getUser()); - return $display; + return phabricator_datetime($this->getValue(), $this->getUser()); + case self::TYPE_REMARKUP: + return $this->getMarkupEngine()->getOutput( + $this, + 'default'); } return parent::renderForDetailView(); } @@ -247,6 +262,10 @@ class ManiphestAuxiliaryFieldDefaultSpecification "from '{$old_display}' to '{$new_display}'"; } break; + case self::TYPE_REMARKUP: + // TODO: After we get ApplicationTransactions, straighten this out. + $desc = "updated field '{$label}'"; + break; default: if (!strlen($old)) { if (!strlen($new)) { diff --git a/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldSpecification.php b/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldSpecification.php index 0eba1db06e..6d1f8d89ad 100644 --- a/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldSpecification.php +++ b/src/applications/maniphest/auxiliaryfield/ManiphestAuxiliaryFieldSpecification.php @@ -3,7 +3,8 @@ /** * @group maniphest */ -abstract class ManiphestAuxiliaryFieldSpecification { +abstract class ManiphestAuxiliaryFieldSpecification + implements PhabricatorMarkupInterface { const RENDER_TARGET_HTML = 'html'; const RENDER_TARGET_TEXT = 'text'; @@ -14,6 +15,7 @@ abstract class ManiphestAuxiliaryFieldSpecification { private $value; private $user; private $task; + private $markupEngine; public function setTask(ManiphestTask $task) { $this->task = $task; @@ -158,4 +160,52 @@ abstract class ManiphestAuxiliaryFieldSpecification { } + public function getMarkupFields() { + return array(); + } + + public function setMarkupEngine(PhabricatorMarkupEngine $engine) { + $this->markupEngine = $engine; + return $this; + } + + public function getMarkupEngine() { + return $this->markupEngine; + } + + +/* -( PhabricatorMarkupInterface )----------------------------------------- */ + + + public function getMarkupFieldKey($field) { + $hash = PhabricatorHash::digestForIndex($this->getMarkupText($field)); + return 'maux:'.$this->getAuxiliaryKey().':'.$hash; + } + + + public function newMarkupEngine($field) { + return PhabricatorMarkupEngine::newManiphestMarkupEngine(); + } + + + public function getMarkupText($field) { + return $this->getValue(); + } + + public function didMarkupText( + $field, + $output, + PhutilMarkupEngine $engine) { + return phutil_tag( + 'div', + array( + 'class' => 'phabricator-remarkup', + ), + $output); + } + + public function shouldUseMarkupCache($field) { + return true; + } + } diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index dc6980c071..0533c75b47 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -126,11 +126,19 @@ final class ManiphestTaskDetailController extends ManiphestController { $engine->addObject($xaction, ManiphestTransaction::MARKUP_FIELD_BODY); } } - $engine->process(); $extensions = ManiphestTaskExtensions::newExtensions(); $aux_fields = $extensions->loadFields($task, $user); + foreach ($aux_fields as $aux_field) { + foreach ($aux_field->getMarkupFields() as $markup_field) { + $engine->addObject($aux_field, $markup_field); + $aux_field->setMarkupEngine($engine); + } + } + + $engine->process(); + $transaction_types = ManiphestTransactionType::getTransactionTypeMap(); $resolution_types = ManiphestTaskStatus::getTaskStatusMap(); diff --git a/src/docs/userguide/maniphest_custom.diviner b/src/docs/userguide/maniphest_custom.diviner index b8f68c35a1..45c079aaac 100644 --- a/src/docs/userguide/maniphest_custom.diviner +++ b/src/docs/userguide/maniphest_custom.diviner @@ -44,8 +44,8 @@ Each array key must be unique, and is used to organize the internal storage of the field. These options are available: - **label**: Display label for the field on the edit and detail interfaces. - - **type**: Field type, one of **int**, **string**, **bool**, **select** or - **date**. + - **type**: Field type, one of **int**, **string**, **bool**, **select**, + **remarkup**, or **date**. - **caption**: A caption to display underneath the field (optional). - **required**: True if the user should be required to provide a value. - **options**: If type is set to **select**, provide options for the dropdown