Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / releeph / field / specification / ReleephFieldSpecification.php
blobff95ed6514e6260a16a910cc6b93e566499fa79a
1 <?php
3 abstract class ReleephFieldSpecification
4 extends PhabricatorCustomField
5 implements PhabricatorMarkupInterface {
7 // TODO: This is temporary, until ReleephFieldSpecification is more conformant
8 // to PhabricatorCustomField.
9 private $requestValue;
11 public function readValueFromRequest(AphrontRequest $request) {
12 $this->requestValue = $request->getStr($this->getRequiredStorageKey());
13 return $this;
16 public function shouldAppearInPropertyView() {
17 return true;
20 public function renderPropertyViewLabel() {
21 return $this->getName();
24 public function renderPropertyViewValue(array $handles) {
25 $key = $this->getRequiredStorageKey();
26 $value = $this->getReleephRequest()->getDetail($key);
27 if ($value === '') {
28 return null;
30 return $value;
33 abstract public function getName();
35 /* -( Storage )------------------------------------------------------------ */
37 public function getStorageKey() {
38 return null;
41 public function getRequiredStorageKey() {
42 $key = $this->getStorageKey();
43 if ($key === null) {
44 throw new PhabricatorCustomFieldImplementationIncompleteException($this);
46 if (strpos($key, '.') !== false) {
47 /**
48 * Storage keys are reused for form controls, and periods in form control
49 * names break HTML forms.
51 throw new Exception(pht("You can't use '%s' in storage keys!", '.'));
53 return $key;
56 public function shouldAppearInEditView() {
57 return $this->isEditable();
60 final public function isEditable() {
61 return $this->getStorageKey() !== null;
64 final public function getValue() {
65 if ($this->requestValue !== null) {
66 return $this->requestValue;
69 $key = $this->getRequiredStorageKey();
70 return $this->getReleephRequest()->getDetail($key);
73 final public function setValue($value) {
74 $key = $this->getRequiredStorageKey();
75 return $this->getReleephRequest()->setDetail($key, $value);
78 /**
79 * @throws ReleephFieldParseException, to show an error.
81 public function validate($value) {
82 return;
85 /**
86 * Turn values as they are stored in a ReleephRequest into a text that can be
87 * rendered as a transactions old/new values.
89 public function normalizeForTransactionView(
90 PhabricatorApplicationTransaction $xaction,
91 $value) {
93 return $value;
97 /* -( Conduit )------------------------------------------------------------ */
99 public function getKeyForConduit() {
100 return $this->getRequiredStorageKey();
103 public function getValueForConduit() {
104 return $this->getValue();
107 public function setValueFromConduitAPIRequest(ConduitAPIRequest $request) {
108 $value = idx(
109 $request->getValue('fields', array()),
110 $this->getRequiredStorageKey());
111 $this->validate($value);
112 $this->setValue($value);
113 return $this;
117 /* -( Arcanist )----------------------------------------------------------- */
119 public function renderHelpForArcanist() {
120 return '';
124 /* -( Context )------------------------------------------------------------ */
126 private $releephProject;
127 private $releephBranch;
128 private $releephRequest;
129 private $user;
131 final public function setReleephProject(ReleephProject $rp) {
132 $this->releephProject = $rp;
133 return $this;
136 final public function setReleephBranch(ReleephBranch $rb) {
137 $this->releephRequest = $rb;
138 return $this;
141 final public function setReleephRequest(ReleephRequest $rr) {
142 $this->releephRequest = $rr;
143 return $this;
146 final public function setUser(PhabricatorUser $user) {
147 $this->user = $user;
148 return $this;
151 final public function getReleephProject() {
152 if (!$this->releephProject) {
153 return $this->getReleephBranch()->getProduct();
155 return $this->releephProject;
158 final public function getReleephBranch() {
159 if (!$this->releephBranch) {
160 return $this->getReleephRequest()->getBranch();
162 return $this->releephBranch;
165 final public function getReleephRequest() {
166 if (!$this->releephRequest) {
167 return $this->getObject();
169 return $this->releephRequest;
172 final public function getUser() {
173 if (!$this->user) {
174 return $this->getViewer();
176 return $this->user;
179 /* -( Commit Messages )---------------------------------------------------- */
181 public function shouldAppearOnCommitMessage() {
182 return false;
185 public function renderLabelForCommitMessage() {
186 throw new PhabricatorCustomFieldImplementationIncompleteException($this);
189 public function renderValueForCommitMessage() {
190 throw new PhabricatorCustomFieldImplementationIncompleteException($this);
193 public function shouldAppearOnRevertMessage() {
194 return false;
197 public function renderLabelForRevertMessage() {
198 return $this->renderLabelForCommitMessage();
201 public function renderValueForRevertMessage() {
202 return $this->renderValueForCommitMessage();
206 /* -( Markup Interface )--------------------------------------------------- */
208 const MARKUP_FIELD_GENERIC = 'releeph:generic-markup-field';
210 private $engine;
213 * @{class:ReleephFieldSpecification} implements much of
214 * @{interface:PhabricatorMarkupInterface} for you. If you return true from
215 * `shouldMarkup()`, and implement `getMarkupText()` then your text will be
216 * rendered through the Phabricator markup pipeline.
218 * Output is retrievable with `getMarkupEngineOutput()`.
220 public function shouldMarkup() {
221 return false;
224 public function getMarkupText($field) {
225 throw new PhabricatorCustomFieldImplementationIncompleteException($this);
228 final public function getMarkupEngineOutput() {
229 return $this->engine->getOutput($this, self::MARKUP_FIELD_GENERIC);
232 final public function setMarkupEngine(PhabricatorMarkupEngine $engine) {
233 $this->engine = $engine;
234 $engine->addObject($this, self::MARKUP_FIELD_GENERIC);
235 return $this;
238 final public function getMarkupFieldKey($field) {
239 $content = sprintf(
240 '%s:%s:%s:%s',
241 $this->getReleephRequest()->getPHID(),
242 $this->getStorageKey(),
243 $field,
244 $this->getMarkupText($field));
246 return PhabricatorMarkupEngine::digestRemarkupContent($this, $content);
249 final public function newMarkupEngine($field) {
250 return PhabricatorMarkupEngine::newDifferentialMarkupEngine();
253 final public function didMarkupText(
254 $field,
255 $output,
256 PhutilMarkupEngine $engine) {
258 return $output;
261 final public function shouldUseMarkupCache($field) {
262 return true;