Path: blob/master/src/applications/differential/field/DifferentialCommitMessageField.php
12256 views
<?php12abstract class DifferentialCommitMessageField3extends Phobject {45private $viewer;6private $customFieldStorage;78final public function setViewer(PhabricatorUser $viewer) {9$this->viewer = $viewer;10return $this;11}1213final public function getViewer() {14return $this->viewer;15}1617final public function setCustomFieldStorage(array $custom_field_storage) {18$this->customFieldStorage = $custom_field_storage;19return $this;20}2122final public function getCustomFieldStorage() {23return $this->customFieldStorage;24}2526abstract public function getFieldName();27abstract public function getFieldOrder();2829public function isFieldEnabled() {30return true;31}3233public function getFieldAliases() {34return array();35}3637public function validateFieldValue($value) {38return;39}4041public function parseFieldValue($value) {42return $value;43}4445public function isFieldEditable() {46return true;47}4849public function isTemplateField() {50return true;51}5253public function readFieldValueFromConduit($value) {54return $this->readStringFieldValueFromConduit($value);55}5657public function readFieldValueFromObject(DifferentialRevision $revision) {58return null;59}6061public function renderFieldValue($value) {62if ($value === null || !strlen($value)) {63return null;64}6566return $value;67}6869public function getFieldTransactions($value) {70if (!$this->isFieldEditable()) {71return array();72}73throw new PhutilMethodNotImplementedException();74}7576final public function getCommitMessageFieldKey() {77return $this->getPhobjectClassConstant('FIELDKEY', 64);78}7980final public static function newEnabledFields(PhabricatorUser $viewer) {81$fields = self::getAllFields();8283$results = array();84foreach ($fields as $key => $field) {85$field = clone $field;86$field->setViewer($viewer);87if ($field->isFieldEnabled()) {88$results[$key] = $field;89}90}9192return $results;93}9495final public static function getAllFields() {96return id(new PhutilClassMapQuery())97->setAncestorClass(__CLASS__)98->setUniqueMethod('getCommitMessageFieldKey')99->setSortMethod('getFieldOrder')100->execute();101}102103protected function raiseParseException($message) {104throw new DifferentialFieldParseException($message);105}106107protected function raiseValidationException($message) {108throw new DifferentialFieldValidationException($message);109}110111protected function parseObjectList(112$value,113array $types,114$allow_partial = false,115array $suffixes = array()) {116return id(new PhabricatorObjectListQuery())117->setViewer($this->getViewer())118->setAllowedTypes($types)119->setObjectList($value)120->setAllowPartialResults($allow_partial)121->setSuffixes($suffixes)122->execute();123}124125protected function renderHandleList(array $phids, array $suffixes = array()) {126if (!$phids) {127return null;128}129130$handles = $this->getViewer()->loadHandles($phids);131132$out = array();133foreach ($handles as $handle) {134$phid = $handle->getPHID();135136if ($handle->getPolicyFiltered()) {137$token = $phid;138} else if ($handle->isComplete()) {139$token = $handle->getCommandLineObjectName();140}141142$suffix = idx($suffixes, $phid);143$token = $token.$suffix;144145$out[] = $token;146}147148return implode(', ', $out);149}150151protected function readStringFieldValueFromConduit($value) {152if ($value === null) {153return $value;154}155156if (!is_string($value)) {157throw new Exception(158pht(159'Field "%s" expects a string value, but received a value of type '.160'"%s".',161$this->getCommitMessageFieldKey(),162gettype($value)));163}164165return $value;166}167168protected function readStringListFieldValueFromConduit($value) {169if (!is_array($value)) {170throw new Exception(171pht(172'Field "%s" expects a list of strings, but received a value of type '.173'"%s".',174$this->getCommitMessageFieldKey(),175gettype($value)));176}177178return $value;179}180181protected function isCustomFieldEnabled($key) {182$field_list = PhabricatorCustomField::getObjectFields(183new DifferentialRevision(),184DifferentialCustomField::ROLE_DEFAULT);185186$fields = $field_list->getFields();187return isset($fields[$key]);188}189190}191192193