Differential D16846 Diff 40568 src/applications/differential/customfield/DifferentialCoreCustomField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/customfield/DifferentialCoreCustomField.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Base class for Differential fields with storage on the revision object | * Base class for Differential fields with storage on the revision object | ||||
| * itself. This mostly wraps reading/writing field values to and from the | * itself. This mostly wraps reading/writing field values to and from the | ||||
| * object. | * object. | ||||
| */ | */ | ||||
| abstract class DifferentialCoreCustomField | abstract class DifferentialCoreCustomField | ||||
| extends DifferentialCustomField { | extends DifferentialCustomField { | ||||
| private $value; | private $value; | ||||
| private $fieldError; | private $fieldError; | ||||
| private $fieldParser; | |||||
| abstract protected function readValueFromRevision( | abstract protected function readValueFromRevision( | ||||
| DifferentialRevision $revision); | DifferentialRevision $revision); | ||||
| protected function writeValueToRevision( | protected function writeValueToRevision( | ||||
| DifferentialRevision $revision, | DifferentialRevision $revision, | ||||
| $value) { | $value) { | ||||
| throw new PhabricatorCustomFieldImplementationIncompleteException($this); | throw new PhabricatorCustomFieldImplementationIncompleteException($this); | ||||
| Show All 34 Lines | foreach ($xactions as $xaction) { | ||||
| $error = new PhabricatorApplicationTransactionValidationError( | $error = new PhabricatorApplicationTransactionValidationError( | ||||
| $type, | $type, | ||||
| pht('Required'), | pht('Required'), | ||||
| $this->getCoreFieldRequiredErrorString(), | $this->getCoreFieldRequiredErrorString(), | ||||
| $xaction); | $xaction); | ||||
| $error->setIsMissingFieldError(true); | $error->setIsMissingFieldError(true); | ||||
| $errors[] = $error; | $errors[] = $error; | ||||
| $this->setFieldError(pht('Required')); | $this->setFieldError(pht('Required')); | ||||
| continue; | |||||
| } | |||||
| } | |||||
| if (is_string($value)) { | |||||
| $parser = $this->getFieldParser(); | |||||
| $result = $parser->parseCorpus($value); | |||||
| unset($result['__title__']); | |||||
| unset($result['__summary__']); | |||||
| if ($result) { | |||||
| $error = new PhabricatorApplicationTransactionValidationError( | |||||
| $type, | |||||
| pht('Invalid'), | |||||
| pht( | |||||
| 'The value you have entered in "%s" can not be parsed '. | |||||
| 'unambiguously when rendered in a commit message. Edit the '. | |||||
| 'message so that keywords like "Summary:" and "Test Plan:" do '. | |||||
| 'not appear at the beginning of lines. Parsed keys: %s.', | |||||
| $this->getFieldName(), | |||||
| implode(', ', array_keys($result))), | |||||
| $xaction); | |||||
| $errors[] = $error; | |||||
| $this->setFieldError(pht('Invalid')); | |||||
| continue; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return $errors; | return $errors; | ||||
| } | } | ||||
| private function getFieldParser() { | |||||
| if (!$this->fieldParser) { | |||||
| $viewer = $this->getViewer(); | |||||
| $parser = DifferentialCommitMessageParser::newStandardParser($viewer); | |||||
| // Set custom title and summary keys so we can detect the presence of | |||||
| // "Summary:" in, e.g., a test plan. | |||||
| $parser->setTitleKey('__title__'); | |||||
| $parser->setSummaryKey('__summary__'); | |||||
| $this->fieldParser = $parser; | |||||
| } | |||||
| return $this->fieldParser; | |||||
| } | |||||
| public function canDisableField() { | public function canDisableField() { | ||||
| return false; | return false; | ||||
| } | } | ||||
| public function shouldAppearInApplicationTransactions() { | public function shouldAppearInApplicationTransactions() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||