@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 185 lines 4.6 kB view raw
1<?php 2 3final class PhabricatorCustomFieldEditField 4 extends PhabricatorEditField { 5 6 private $customField; 7 private $httpParameterType; 8 private $conduitParameterType; 9 private $bulkParameterType; 10 private $commentAction; 11 12 public function setCustomField(PhabricatorCustomField $custom_field) { 13 $this->customField = $custom_field; 14 return $this; 15 } 16 17 public function getCustomField() { 18 return $this->customField; 19 } 20 21 public function setCustomFieldHTTPParameterType( 22 AphrontHTTPParameterType $type) { 23 $this->httpParameterType = $type; 24 return $this; 25 } 26 27 public function getCustomFieldHTTPParameterType() { 28 return $this->httpParameterType; 29 } 30 31 public function setCustomFieldConduitParameterType( 32 ConduitParameterType $type) { 33 $this->conduitParameterType = $type; 34 return $this; 35 } 36 37 public function getCustomFieldConduitParameterType() { 38 return $this->conduitParameterType; 39 } 40 41 public function setCustomFieldBulkParameterType( 42 BulkParameterType $type) { 43 $this->bulkParameterType = $type; 44 return $this; 45 } 46 47 public function getCustomFieldBulkParameterType() { 48 return $this->bulkParameterType; 49 } 50 51 public function setCustomFieldCommentAction( 52 PhabricatorEditEngineCommentAction $comment_action) { 53 $this->commentAction = $comment_action; 54 return $this; 55 } 56 57 public function getCustomFieldCommentAction() { 58 return $this->commentAction; 59 } 60 61 protected function buildControl() { 62 if (!$this->getIsFormField()) { 63 return null; 64 } 65 66 $field = $this->getCustomField(); 67 $clone = clone $field; 68 69 $value = $this->getValue(); 70 $clone->setValueFromApplicationTransactions($value); 71 72 return $clone->renderEditControl(array()); 73 } 74 75 protected function newEditType() { 76 return id(new PhabricatorCustomFieldEditType()) 77 ->setCustomField($this->getCustomField()); 78 } 79 80 public function getValueForTransaction() { 81 $value = $this->getValue(); 82 $field = $this->getCustomField(); 83 84 // Avoid changing the value of the field itself, since later calls would 85 // incorrectly reflect the new value. 86 $clone = clone $field; 87 $clone->setValueFromApplicationTransactions($value); 88 return $clone->getNewValueForApplicationTransactions(); 89 } 90 91 protected function getValueForCommentAction($value) { 92 $field = $this->getCustomField(); 93 $clone = clone $field; 94 $clone->setValueFromApplicationTransactions($value); 95 96 // TODO: This is somewhat bogus because only StandardCustomFields 97 // implement a getFieldValue() method -- not all CustomFields. Today, 98 // only StandardCustomFields can ever actually generate a comment action 99 // so we never reach this method with other field types. 100 101 return $clone->getFieldValue(); 102 } 103 104 protected function getValueExistsInSubmit(AphrontRequest $request, $key) { 105 return true; 106 } 107 108 protected function getValueFromSubmit(AphrontRequest $request, $key) { 109 $field = $this->getCustomField(); 110 111 $clone = clone $field; 112 113 $clone->readValueFromRequest($request); 114 return $clone->getNewValueForApplicationTransactions(); 115 } 116 117 protected function newConduitEditTypes() { 118 $field = $this->getCustomField(); 119 120 if (!$field->shouldAppearInConduitTransactions()) { 121 return array(); 122 } 123 124 return parent::newConduitEditTypes(); 125 } 126 127 protected function newHTTPParameterType() { 128 $type = $this->getCustomFieldHTTPParameterType(); 129 130 if ($type) { 131 return clone $type; 132 } 133 134 return null; 135 } 136 137 protected function newCommentAction() { 138 $action = $this->getCustomFieldCommentAction(); 139 140 if ($action) { 141 return clone $action; 142 } 143 144 return null; 145 } 146 147 protected function newConduitParameterType() { 148 $type = $this->getCustomFieldConduitParameterType(); 149 150 if ($type) { 151 return clone $type; 152 } 153 154 return null; 155 } 156 157 protected function newBulkParameterType() { 158 $type = $this->getCustomFieldBulkParameterType(); 159 160 if ($type) { 161 return clone $type; 162 } 163 164 return null; 165 } 166 167 public function getAllReadValueFromRequestKeys() { 168 $keys = array(); 169 170 // NOTE: This piece of complexity is so we can expose a reasonable key in 171 // the UI ("custom.x") instead of a crufty internal key ("std:app:x"). 172 // Perhaps we can simplify this some day. 173 174 // In the parent, this is just getKey(), but that returns a cumbersome 175 // key in EditFields. Use the simpler edit type key instead. 176 $keys[] = $this->getEditTypeKey(); 177 178 foreach ($this->getAliases() as $alias) { 179 $keys[] = $alias; 180 } 181 182 return $keys; 183 } 184 185}