Differential D8291 Diff 19730 src/applications/differential/customfield/DifferentialReviewersField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/customfield/DifferentialReviewersField.php
- This file was added.
| <?php | |||||
| final class DifferentialReviewersField | |||||
| extends DifferentialCoreCustomField { | |||||
| public function getFieldKey() { | |||||
| return 'differential:reviewers'; | |||||
| } | |||||
| public function getFieldName() { | |||||
| return pht('Reviewers'); | |||||
| } | |||||
| public function getFieldDescription() { | |||||
| return pht('Manage reviewers.'); | |||||
| } | |||||
| protected function readValueFromRevision( | |||||
| DifferentialRevision $revision) { | |||||
| return $revision->getReviewerStatus(); | |||||
| } | |||||
| public function getNewValueForApplicationTransactions() { | |||||
| $specs = array(); | |||||
| foreach ($this->getValue() as $reviewer) { | |||||
| $specs[$reviewer->getReviewerPHID()] = array( | |||||
| 'data' => $reviewer->getEdgeData(), | |||||
| ); | |||||
| } | |||||
| return array('=' => $specs); | |||||
| } | |||||
| public function readValueFromRequest(AphrontRequest $request) { | |||||
| // Compute a new set of reviewer objects. For reviewers who haven't been | |||||
| // added or removed, retain their existing status. Also, respect the new | |||||
| // order. | |||||
| $old_status = $this->getValue(); | |||||
| $old_status = mpull($old_status, null, 'getReviewerPHID'); | |||||
| $new_phids = $request->getArr($this->getFieldKey()); | |||||
| $new_phids = array_fuse($new_phids); | |||||
| $new_status = array(); | |||||
| foreach ($new_phids as $new_phid) { | |||||
| if (empty($old_status[$new_phid])) { | |||||
| $new_status[$new_phid] = new DifferentialReviewer( | |||||
| $new_phid, | |||||
| array( | |||||
| 'status' => DifferentialReviewerStatus::STATUS_ADDED, | |||||
| )); | |||||
| } else { | |||||
| $new_status[$new_phid] = $old_status[$new_phid]; | |||||
| } | |||||
| } | |||||
| $this->setValue($new_status); | |||||
| } | |||||
| public function getRequiredHandlePHIDsForEdit() { | |||||
| return mpull($this->getValue(), 'getReviewerPHID'); | |||||
| } | |||||
| public function renderEditControl(array $handles) { | |||||
| return id(new AphrontFormTokenizerControl()) | |||||
| ->setName($this->getFieldKey()) | |||||
| ->setDatasource('/typeahead/common/usersorprojects/') | |||||
| ->setValue($handles) | |||||
| ->setError($this->getFieldError()) | |||||
| ->setLabel($this->getFieldName()); | |||||
| } | |||||
| public function getApplicationTransactionType() { | |||||
| return PhabricatorTransactions::TYPE_EDGE; | |||||
| } | |||||
| public function getApplicationTransactionMetadata() { | |||||
| return array( | |||||
| 'edge:type' => PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER, | |||||
| ); | |||||
| } | |||||
| } | |||||