Differential D17066 Diff 41082 src/applications/differential/field/DifferentialCommitMessageField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/field/DifferentialCommitMessageField.php
| <?php | <?php | ||||
| abstract class DifferentialCommitMessageField | abstract class DifferentialCommitMessageField | ||||
| extends Phobject { | extends Phobject { | ||||
| private $viewer; | private $viewer; | ||||
| private $customFieldStorage; | |||||
| final public function setViewer(PhabricatorUser $viewer) { | final public function setViewer(PhabricatorUser $viewer) { | ||||
| $this->viewer = $viewer; | $this->viewer = $viewer; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function getViewer() { | final public function getViewer() { | ||||
| return $this->viewer; | return $this->viewer; | ||||
| } | } | ||||
| final public function setCustomFieldStorage(array $custom_field_storage) { | |||||
| $this->customFieldStorage = $custom_field_storage; | |||||
| return $this; | |||||
| } | |||||
| final public function getCustomFieldStorage() { | |||||
| return $this->customFieldStorage; | |||||
| } | |||||
| abstract public function getFieldName(); | abstract public function getFieldName(); | ||||
| abstract public function getFieldOrder(); | |||||
| public function isFieldEnabled() { | public function isFieldEnabled() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function getFieldAliases() { | public function getFieldAliases() { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| public function validateFieldValue($value) { | public function validateFieldValue($value) { | ||||
| return; | return; | ||||
| } | } | ||||
| public function parseFieldValue($value) { | public function parseFieldValue($value) { | ||||
| return $value; | return $value; | ||||
| } | } | ||||
| public function isFieldEditable() { | |||||
| return true; | |||||
| } | |||||
| public function isTemplateField() { | |||||
| return true; | |||||
| } | |||||
| public function readFieldValueFromConduit($value) { | |||||
| return $this->readStringFieldValueFromConduit($value); | |||||
| } | |||||
| public function readFieldValueFromObject(DifferentialRevision $revision) { | |||||
| return null; | |||||
| } | |||||
| public function renderFieldValue($value) { | |||||
| if (!strlen($value)) { | |||||
| return null; | |||||
| } | |||||
| return $value; | |||||
| } | |||||
| final public function getCommitMessageFieldKey() { | final public function getCommitMessageFieldKey() { | ||||
| return $this->getPhobjectClassConstant('FIELDKEY', 64); | return $this->getPhobjectClassConstant('FIELDKEY', 64); | ||||
| } | } | ||||
| final public static function newEnabledFields(PhabricatorUser $viewer) { | final public static function newEnabledFields(PhabricatorUser $viewer) { | ||||
| $fields = self::getAllFields(); | $fields = self::getAllFields(); | ||||
| $results = array(); | $results = array(); | ||||
| foreach ($fields as $key => $field) { | foreach ($fields as $key => $field) { | ||||
| $field = clone $field; | $field = clone $field; | ||||
| $field->setViewer($viewer); | $field->setViewer($viewer); | ||||
| if ($field->isFieldEnabled()) { | if ($field->isFieldEnabled()) { | ||||
| $results[$key] = $field; | $results[$key] = $field; | ||||
| } | } | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| final public static function getAllFields() { | final public static function getAllFields() { | ||||
| return id(new PhutilClassMapQuery()) | return id(new PhutilClassMapQuery()) | ||||
| ->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
| ->setUniqueMethod('getCommitMessageFieldKey') | ->setUniqueMethod('getCommitMessageFieldKey') | ||||
| ->setSortMethod('getFieldOrder') | |||||
| ->execute(); | ->execute(); | ||||
| } | } | ||||
| protected function raiseParseException($message) { | protected function raiseParseException($message) { | ||||
| throw new DifferentialFieldParseException($message); | throw new DifferentialFieldParseException($message); | ||||
| } | } | ||||
| protected function raiseValidationException($message) { | protected function raiseValidationException($message) { | ||||
| Show All 9 Lines | return id(new PhabricatorObjectListQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->setAllowedTypes($types) | ->setAllowedTypes($types) | ||||
| ->setObjectList($value) | ->setObjectList($value) | ||||
| ->setAllowPartialResults($allow_partial) | ->setAllowPartialResults($allow_partial) | ||||
| ->setSuffixes($suffixes) | ->setSuffixes($suffixes) | ||||
| ->execute(); | ->execute(); | ||||
| } | } | ||||
| protected function renderHandleList(array $phids, array $suffixes = array()) { | |||||
| if (!$phids) { | |||||
| return null; | |||||
| } | |||||
| $handles = $this->getViewer()->loadHandles($phids); | |||||
| $out = array(); | |||||
| foreach ($handles as $handle) { | |||||
| $phid = $handle->getPHID(); | |||||
| if ($handle->getPolicyFiltered()) { | |||||
| $token = $phid; | |||||
| } else if ($handle->isComplete()) { | |||||
| $token = $handle->getCommandLineObjectName(); | |||||
| } | |||||
| $suffix = idx($suffixes, $phid); | |||||
| $token = $token.$suffix; | |||||
| $out[] = $token; | |||||
| } | |||||
| return implode(', ', $out); | |||||
| } | |||||
| protected function readStringFieldValueFromConduit($value) { | |||||
| if ($value === null) { | |||||
| return $value; | |||||
| } | |||||
| if (!is_string($value)) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Field "%s" expects a string value, but received a value of type '. | |||||
| '"%s".', | |||||
| $this->getCommitMessageFieldKey(), | |||||
| gettype($value))); | |||||
| } | |||||
| return $value; | |||||
| } | |||||
| protected function readStringListFieldValueFromConduit($value) { | |||||
| if (!is_array($value)) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Field "%s" expects a list of strings, but received a value of type '. | |||||
| '"%s".', | |||||
| $this->getCommitMessageFieldKey(), | |||||
| gettype($value))); | |||||
| } | |||||
| return $value; | |||||
| } | |||||
| protected function isCustomFieldEnabled($key) { | protected function isCustomFieldEnabled($key) { | ||||
| $field_list = PhabricatorCustomField::getObjectFields( | $field_list = PhabricatorCustomField::getObjectFields( | ||||
| new DifferentialRevision(), | new DifferentialRevision(), | ||||
| PhabricatorCustomField::ROLE_VIEW); | PhabricatorCustomField::ROLE_VIEW); | ||||
| $fields = $field_list->getFields(); | $fields = $field_list->getFields(); | ||||
| return isset($fields[$key]); | return isset($fields[$key]); | ||||
| } | } | ||||
| } | } | ||||