Page MenuHomePhabricator

D8283.diff
No OneTemporary

D8283.diff

Index: src/__phutil_library_map__.php
===================================================================
--- src/__phutil_library_map__.php
+++ src/__phutil_library_map__.php
@@ -355,6 +355,7 @@
'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 @@
'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 @@
'DifferentialCommitsFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialConflictsFieldSpecification' => 'DifferentialFieldSpecification',
'DifferentialController' => 'PhabricatorController',
+ 'DifferentialCoreCustomField' => 'DifferentialCustomField',
'DifferentialCustomField' => 'PhabricatorCustomField',
'DifferentialCustomFieldDependsOnParser' => 'PhabricatorCustomFieldMonogramParser',
'DifferentialCustomFieldDependsOnParserTestCase' => 'PhabricatorTestCase',
@@ -3003,9 +3006,10 @@
'DifferentialRevisionViewController' => 'DifferentialController',
'DifferentialSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
'DifferentialSubscribeController' => 'DifferentialController',
+ 'DifferentialSummaryField' => 'DifferentialCoreCustomField',
'DifferentialSummaryFieldSpecification' => 'DifferentialFreeformFieldSpecification',
'DifferentialTestPlanFieldSpecification' => 'DifferentialFieldSpecification',
- 'DifferentialTitleField' => 'DifferentialCustomField',
+ 'DifferentialTitleField' => 'DifferentialCoreCustomField',
'DifferentialTitleFieldSpecification' => 'DifferentialFreeformFieldSpecification',
'DifferentialTransaction' => 'PhabricatorApplicationTransaction',
'DifferentialTransactionComment' => 'PhabricatorApplicationTransactionComment',
Index: src/applications/differential/customfield/DifferentialCoreCustomField.php
===================================================================
--- /dev/null
+++ src/applications/differential/customfield/DifferentialCoreCustomField.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * Base class for Differential fields with storage on the revision object
+ * itself. This mostly wraps reading/writing field values to and from the
+ * object.
+ */
+abstract class DifferentialCoreCustomField
+ extends DifferentialCustomField {
+
+ private $value;
+ private $fieldError;
+
+ abstract protected function readValueFromRevision(
+ DifferentialRevision $revision);
+
+ abstract protected function writeValueToRevision(
+ DifferentialRevision $revision,
+ $value);
+
+ public function isCoreFieldRequired() {
+ return false;
+ }
+
+ public function canDisableField() {
+ return false;
+ }
+
+ public function shouldAppearInApplicationTransactions() {
+ return true;
+ }
+
+ public function shouldAppearInEditView() {
+ return true;
+ }
+
+ protected function didSetObject(PhabricatorCustomFieldInterface $object) {
+ if ($this->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;
+ }
+
+}
Index: src/applications/differential/customfield/DifferentialSummaryField.php
===================================================================
--- /dev/null
+++ src/applications/differential/customfield/DifferentialSummaryField.php
@@ -0,0 +1,69 @@
+<?php
+
+final class DifferentialSummaryField
+ extends DifferentialCoreCustomField {
+
+ public function getFieldKey() {
+ return 'differential:summary';
+ }
+
+ public function getFieldName() {
+ return pht('Summary');
+ }
+
+ public function getFieldDescription() {
+ return pht('Stores a summary of the revision.');
+ }
+
+ protected function readValueFromRevision(
+ DifferentialRevision $revision) {
+ return $revision->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.
+
+}
Index: src/applications/differential/customfield/DifferentialTitleField.php
===================================================================
--- src/applications/differential/customfield/DifferentialTitleField.php
+++ src/applications/differential/customfield/DifferentialTitleField.php
@@ -1,19 +1,7 @@
<?php
final class DifferentialTitleField
- extends DifferentialCustomField {
-
- private $value;
- private $fieldError = true;
-
- public function setFieldError($field_error) {
- $this->fieldError = $field_error;
- return $this;
- }
-
- public function getFieldError() {
- return $this->fieldError;
- }
+ extends DifferentialCoreCustomField {
public function getFieldKey() {
return 'differential:title';
@@ -27,28 +15,15 @@
return pht('Stores the revision title.');
}
- public function canDisableField() {
- return false;
- }
-
- public function shouldAppearInApplicationTransactions() {
- return true;
- }
-
- public function shouldAppearInEditView() {
- return true;
+ protected function readValueFromRevision(
+ DifferentialRevision $revision) {
+ return $revision->getTitle();
}
- 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 @@
}
}
- 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 @@
}
}
-
}
Index: src/applications/differential/storage/DifferentialRevision.php
===================================================================
--- src/applications/differential/storage/DifferentialRevision.php
+++ src/applications/differential/storage/DifferentialRevision.php
@@ -465,10 +465,13 @@
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));
}

File Metadata

Mime Type
text/plain
Expires
Sun, May 12, 3:22 AM (3 w, 22 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6285390
Default Alt Text
D8283.diff (10 KB)

Event Timeline