Differential D14634 Diff 35411 src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/customfield/editor/PhabricatorCustomFieldEditField.php
| <?php | <?php | ||||
| final class PhabricatorCustomFieldEditField | final class PhabricatorCustomFieldEditField | ||||
| extends PhabricatorEditField { | extends PhabricatorEditField { | ||||
| private $customField; | private $customField; | ||||
| private $httpParameterType; | |||||
| public function setCustomField(PhabricatorCustomField $custom_field) { | public function setCustomField(PhabricatorCustomField $custom_field) { | ||||
| $this->customField = $custom_field; | $this->customField = $custom_field; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getCustomField() { | public function getCustomField() { | ||||
| return $this->customField; | return $this->customField; | ||||
| } | } | ||||
| public function setCustomFieldHTTPParameterType( | |||||
| AphrontHTTPParameterType $type) { | |||||
| $this->httpParameterType = $type; | |||||
| return $this; | |||||
| } | |||||
| public function getCustomFieldHTTPParameterType() { | |||||
| return $this->httpParameterType; | |||||
| } | |||||
| protected function buildControl() { | protected function buildControl() { | ||||
| $field = $this->getCustomField(); | $field = $this->getCustomField(); | ||||
| $clone = clone $field; | $clone = clone $field; | ||||
| if ($this->getIsSubmittedForm()) { | |||||
| $value = $this->getValue(); | $value = $this->getValue(); | ||||
| $clone->setValueFromApplicationTransactions($value); | $clone->setValueFromApplicationTransactions($value); | ||||
| } | |||||
| return $clone->renderEditControl(array()); | return $clone->renderEditControl(array()); | ||||
| } | } | ||||
| protected function newEditType() { | protected function newEditType() { | ||||
| return id(new PhabricatorCustomFieldEditType()) | return id(new PhabricatorCustomFieldEditType()) | ||||
| ->setCustomField($this->getCustomField()); | ->setCustomField($this->getCustomField()); | ||||
| } | } | ||||
| public function getValueForTransaction() { | public function getValueForTransaction() { | ||||
| $value = $this->getValue(); | $value = $this->getValue(); | ||||
| $field = $this->getCustomField(); | $field = $this->getCustomField(); | ||||
| // Avoid changing the value of the field itself, since later calls would | // Avoid changing the value of the field itself, since later calls would | ||||
| // incorrectly reflect the new value. | // incorrectly reflect the new value. | ||||
| $clone = clone $field; | $clone = clone $field; | ||||
| $clone->setValueFromApplicationTransactions($value); | $clone->setValueFromApplicationTransactions($value); | ||||
| return $clone->getNewValueForApplicationTransactions(); | return $clone->getNewValueForApplicationTransactions(); | ||||
| } | } | ||||
| protected function getValueExistsInRequest(AphrontRequest $request, $key) { | |||||
| // For now, never read these out of the request. | |||||
| return false; | |||||
| } | |||||
| protected function getValueExistsInSubmit(AphrontRequest $request, $key) { | protected function getValueExistsInSubmit(AphrontRequest $request, $key) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| protected function getValueFromSubmit(AphrontRequest $request, $key) { | protected function getValueFromSubmit(AphrontRequest $request, $key) { | ||||
| $field = $this->getCustomField(); | $field = $this->getCustomField(); | ||||
| $clone = clone $field; | $clone = clone $field; | ||||
| $clone->readValueFromRequest($request); | $clone->readValueFromRequest($request); | ||||
| return $clone->getNewValueForApplicationTransactions(); | return $clone->getNewValueForApplicationTransactions(); | ||||
| } | } | ||||
| public function getConduitEditTypes() { | public function getConduitEditTypes() { | ||||
| // TODO: For now, don't support custom fields over Conduit. | // TODO: For now, don't support custom fields over Conduit. | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| protected function newHTTPParameterType() { | protected function newHTTPParameterType() { | ||||
| // TODO: For now, don't support custom fields for HTTP prefill. | $type = $this->getCustomFieldHTTPParameterType(); | ||||
| if ($type) { | |||||
| return clone $type; | |||||
| } | |||||
| return null; | return null; | ||||
| } | } | ||||
| public function getAllReadValueFromRequestKeys() { | |||||
| $keys = array(); | |||||
| // NOTE: This piece of complexity is so we can expose a reasonable key in | |||||
| // the UI ("custom.x") instead of a crufty internal key ("std:app:x"). | |||||
| // Perhaps we can simplify this some day. | |||||
| // In the parent, this is just getKey(), but that returns a cumbersome | |||||
| // key in EditFields. Use the simpler edit type key instead. | |||||
| $keys[] = $this->getEditTypeKey(); | |||||
| foreach ($this->getAliases() as $alias) { | |||||
| $keys[] = $alias; | |||||
| } | |||||
| return $keys; | |||||
| } | |||||
| } | } | ||||