From be262f4b0c1646f761b8af77946b6d278954cf6e Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 21 Feb 2014 11:52:52 -0800 Subject: [PATCH] Implement new-style "Summary" field Summary: Ref T3886. - Adds "Summary" field. - Adds "CoreField" for fields stored on the actual object, to reduce code duplication a bit for the main fields. Test Plan: {F115902} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3886 Differential Revision: https://secure.phabricator.com/D8283 --- src/__phutil_library_map__.php | 6 +- .../DifferentialCoreCustomField.php | 75 +++++++++++++++++++ .../customfield/DifferentialSummaryField.php | 69 +++++++++++++++++ .../customfield/DifferentialTitleField.php | 51 +++---------- .../storage/DifferentialRevision.php | 9 ++- 5 files changed, 165 insertions(+), 45 deletions(-) create mode 100644 src/applications/differential/customfield/DifferentialCoreCustomField.php create mode 100644 src/applications/differential/customfield/DifferentialSummaryField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 44f4896a3e..06ed67d6b8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -355,6 +355,7 @@ phutil_register_library_map(array( 'DifferentialCommitsFieldSpecification' => 'applications/differential/field/specification/DifferentialCommitsFieldSpecification.php', 'DifferentialConflictsFieldSpecification' => 'applications/differential/field/specification/DifferentialConflictsFieldSpecification.php', 'DifferentialController' => 'applications/differential/controller/DifferentialController.php', + 'DifferentialCoreCustomField' => 'applications/differential/customfield/DifferentialCoreCustomField.php', 'DifferentialCustomField' => 'applications/differential/customfield/DifferentialCustomField.php', 'DifferentialCustomFieldDependsOnParser' => 'applications/differential/field/parser/DifferentialCustomFieldDependsOnParser.php', 'DifferentialCustomFieldDependsOnParserTestCase' => 'applications/differential/field/parser/__tests__/DifferentialCustomFieldDependsOnParserTestCase.php', @@ -461,6 +462,7 @@ phutil_register_library_map(array( 'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php', 'DifferentialSearchIndexer' => 'applications/differential/search/DifferentialSearchIndexer.php', 'DifferentialSubscribeController' => 'applications/differential/controller/DifferentialSubscribeController.php', + 'DifferentialSummaryField' => 'applications/differential/customfield/DifferentialSummaryField.php', 'DifferentialSummaryFieldSpecification' => 'applications/differential/field/specification/DifferentialSummaryFieldSpecification.php', 'DifferentialTasksAttacher' => 'applications/differential/DifferentialTasksAttacher.php', 'DifferentialTestPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialTestPlanFieldSpecification.php', @@ -2891,6 +2893,7 @@ phutil_register_library_map(array( 'DifferentialCommitsFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialConflictsFieldSpecification' => 'DifferentialFieldSpecification', 'DifferentialController' => 'PhabricatorController', + 'DifferentialCoreCustomField' => 'DifferentialCustomField', 'DifferentialCustomField' => 'PhabricatorCustomField', 'DifferentialCustomFieldDependsOnParser' => 'PhabricatorCustomFieldMonogramParser', 'DifferentialCustomFieldDependsOnParserTestCase' => 'PhabricatorTestCase', @@ -3003,9 +3006,10 @@ phutil_register_library_map(array( 'DifferentialRevisionViewController' => 'DifferentialController', 'DifferentialSearchIndexer' => 'PhabricatorSearchDocumentIndexer', 'DifferentialSubscribeController' => 'DifferentialController', + 'DifferentialSummaryField' => 'DifferentialCoreCustomField', 'DifferentialSummaryFieldSpecification' => 'DifferentialFreeformFieldSpecification', 'DifferentialTestPlanFieldSpecification' => 'DifferentialFieldSpecification', - 'DifferentialTitleField' => 'DifferentialCustomField', + 'DifferentialTitleField' => 'DifferentialCoreCustomField', 'DifferentialTitleFieldSpecification' => 'DifferentialFreeformFieldSpecification', 'DifferentialTransaction' => 'PhabricatorApplicationTransaction', 'DifferentialTransactionComment' => 'PhabricatorApplicationTransactionComment', diff --git a/src/applications/differential/customfield/DifferentialCoreCustomField.php b/src/applications/differential/customfield/DifferentialCoreCustomField.php new file mode 100644 index 0000000000..2292fa970c --- /dev/null +++ b/src/applications/differential/customfield/DifferentialCoreCustomField.php @@ -0,0 +1,75 @@ +isCoreFieldRequired()) { + $this->setFieldError(true); + } + $this->setValue($this->readValueFromRevision($object)); + } + + public function getOldValueForApplicationTransactions() { + return $this->readValueFromRevision($this->getObject()); + } + + public function getNewValueForApplicationTransactions() { + return $this->getValue(); + } + + public function applyApplicationTransactionInternalEffects( + PhabricatorApplicationTransaction $xaction) { + $this->writeValueToRevision($this->getObject(), $xaction->getNewValue()); + } + + public function setFieldError($field_error) { + $this->fieldError = $field_error; + return $this; + } + + public function getFieldError() { + return $this->fieldError; + } + + public function setValue($value) { + $this->value = $value; + return $this; + } + + public function getValue() { + return $this->value; + } + +} diff --git a/src/applications/differential/customfield/DifferentialSummaryField.php b/src/applications/differential/customfield/DifferentialSummaryField.php new file mode 100644 index 0000000000..88f6cb779d --- /dev/null +++ b/src/applications/differential/customfield/DifferentialSummaryField.php @@ -0,0 +1,69 @@ +getSummary(); + } + + protected function writeValueToRevision( + DifferentialRevision $revision, + $value) { + $revision->setSummary($value); + } + + public function readValueFromRequest(AphrontRequest $request) { + $this->setValue($request->getStr($this->getFieldKey())); + } + + public function renderEditControl() { + return id(new PhabricatorRemarkupControl()) + ->setName($this->getFieldKey()) + ->setValue($this->getValue()) + ->setError($this->getFieldError()) + ->setLabel($this->getFieldName()); + } + + public function getApplicationTransactionTitle( + PhabricatorApplicationTransaction $xaction) { + $author_phid = $xaction->getAuthorPHID(); + $old = $xaction->getOldValue(); + $new = $xaction->getNewValue(); + + return pht( + '%s updated the summary for this revision.', + $xaction->renderHandleLink($author_phid)); + } + + public function getApplicationTransactionTitleForFeed( + PhabricatorApplicationTransaction $xaction, + PhabricatorFeedStory $story) { + + $object_phid = $xaction->getObjectPHID(); + $author_phid = $xaction->getAuthorPHID(); + $old = $xaction->getOldValue(); + $new = $xaction->getNewValue(); + + return pht( + '%s updated the summary for %s.', + $xaction->renderHandleLink($author_phid), + $xaction->renderHandleLink($object_phid)); + } + + // TODO: Support hasChangeDetails() in CustomFields. + +} diff --git a/src/applications/differential/customfield/DifferentialTitleField.php b/src/applications/differential/customfield/DifferentialTitleField.php index bcf2650b57..e8281f6128 100644 --- a/src/applications/differential/customfield/DifferentialTitleField.php +++ b/src/applications/differential/customfield/DifferentialTitleField.php @@ -1,19 +1,7 @@ fieldError = $field_error; - return $this; - } - - public function getFieldError() { - return $this->fieldError; - } + extends DifferentialCoreCustomField { public function getFieldKey() { return 'differential:title'; @@ -27,28 +15,15 @@ final class DifferentialTitleField return pht('Stores the revision title.'); } - public function canDisableField() { - return false; + protected function readValueFromRevision( + DifferentialRevision $revision) { + return $revision->getTitle(); } - public function shouldAppearInApplicationTransactions() { - return true; - } - - public function shouldAppearInEditView() { - return true; - } - - protected function didSetObject(PhabricatorCustomFieldInterface $object) { - $this->value = $object->getTitle(); - } - - public function getOldValueForApplicationTransactions() { - return $this->getObject()->getTitle(); - } - - public function getNewValueForApplicationTransactions() { - return $this->value; + protected function writeValueToRevision( + DifferentialRevision $revision, + $value) { + $revision->setTitle($value); } public function validateApplicationTransactions( @@ -77,20 +52,15 @@ final class DifferentialTitleField } } - public function applyApplicationTransactionInternalEffects( - PhabricatorApplicationTransaction $xaction) { - $this->getObject()->setTitle($xaction->getNewValue()); - } - public function readValueFromRequest(AphrontRequest $request) { - $this->value = $request->getStr($this->getFieldKey()); + $this->setValue($request->getStr($this->getFieldKey())); } public function renderEditControl() { return id(new AphrontFormTextAreaControl()) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT) ->setName($this->getFieldKey()) - ->setValue($this->value) + ->setValue($this->getValue()) ->setError($this->getFieldError()) ->setLabel($this->getFieldName()); } @@ -138,5 +108,4 @@ final class DifferentialTitleField } } - } diff --git a/src/applications/differential/storage/DifferentialRevision.php b/src/applications/differential/storage/DifferentialRevision.php index 79c73c58b0..48fd3cdc12 100644 --- a/src/applications/differential/storage/DifferentialRevision.php +++ b/src/applications/differential/storage/DifferentialRevision.php @@ -465,10 +465,13 @@ final class DifferentialRevision extends DifferentialDAO public function getCustomFieldSpecificationForRole($role) { - return array_fill_keys( - array( + $fields = array( + new DifferentialTitleField(), + new DifferentialSummaryField(), + ); - ), + return array_fill_keys( + mpull($fields, 'getFieldKey'), array('disabled' => false)); }