Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editfield/PhabricatorEditField.php
| Show All 10 Lines | abstract class PhabricatorEditField extends Phobject { | ||||
| private $object; | private $object; | ||||
| private $transactionType; | private $transactionType; | ||||
| private $metadata = array(); | private $metadata = array(); | ||||
| private $description; | private $description; | ||||
| private $editTypeKey; | private $editTypeKey; | ||||
| private $isLocked; | private $isLocked; | ||||
| private $isPreview; | private $isPreview; | ||||
| private $isReorderable = true; | private $isReorderable = true; | ||||
| private $isEditDefaults; | |||||
| private $isDefaultable = true; | |||||
| public function setKey($key) { | public function setKey($key) { | ||||
| $this->key = $key; | $this->key = $key; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getKey() { | public function getKey() { | ||||
| return $this->key; | return $this->key; | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | public function setIsReorderable($is_reorderable) { | ||||
| $this->isReorderable = $is_reorderable; | $this->isReorderable = $is_reorderable; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getIsReorderable() { | public function getIsReorderable() { | ||||
| return $this->isReorderable; | return $this->isReorderable; | ||||
| } | } | ||||
| public function setIsEditDefaults($is_edit_defaults) { | |||||
| $this->isEditDefaults = $is_edit_defaults; | |||||
| return $this; | |||||
| } | |||||
| public function getIsEditDefaults() { | |||||
| return $this->isEditDefaults; | |||||
| } | |||||
| public function setIsDefaultable($is_defaultable) { | |||||
| $this->isDefaultable = $is_defaultable; | |||||
| return $this; | |||||
| } | |||||
| public function getIsDefaultable() { | |||||
| return $this->isDefaultable; | |||||
| } | |||||
| protected function newControl() { | protected function newControl() { | ||||
| throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
| } | } | ||||
| protected function renderControl() { | protected function renderControl() { | ||||
| $control = $this->newControl(); | $control = $this->newControl(); | ||||
| if ($control === null) { | if ($control === null) { | ||||
| return null; | return null; | ||||
| } | } | ||||
| $control | $control | ||||
| ->setValue($this->getValueForControl()) | ->setValue($this->getValueForControl()) | ||||
| ->setName($this->getKey()); | ->setName($this->getKey()); | ||||
| if (!$control->getLabel()) { | if (!$control->getLabel()) { | ||||
| $control->setLabel($this->getLabel()); | $control->setLabel($this->getLabel()); | ||||
| } | } | ||||
| if ($this->getIsLocked() || $this->getIsPreview()) { | if ($this->getIsPreview()) { | ||||
| $control->setDisabled(true); | $disabled = true; | ||||
| } else if ($this->getIsEditDefaults()) { | |||||
| $disabled = false; | |||||
| } else { | |||||
| $disabled = $this->getIsLocked(); | |||||
| } | } | ||||
| $control->setDisabled($disabled); | |||||
| return $control; | return $control; | ||||
| } | } | ||||
| public function appendToForm(AphrontFormView $form) { | public function appendToForm(AphrontFormView $form) { | ||||
| $control = $this->renderControl(); | $control = $this->renderControl(); | ||||
| if ($control !== null) { | if ($control !== null) { | ||||
| $form->appendControl($control); | $form->appendControl($control); | ||||
| } | } | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getValueForControl() { | protected function getValueForControl() { | ||||
| return $this->getValue(); | return $this->getValue(); | ||||
| } | } | ||||
| public function getValueForDefaults() { | |||||
| $value = $this->getValue(); | |||||
| // By default, just treat the empty string like `null` since they're | |||||
| // equivalent for almost all fields and this reduces the number of | |||||
| // meaningless transactions we generate when adjusting defaults. | |||||
| if ($value === '') { | |||||
| return null; | |||||
| } | |||||
| return $value; | |||||
| } | |||||
| protected function getValue() { | protected function getValue() { | ||||
| return $this->value; | return $this->value; | ||||
| } | } | ||||
| public function setValue($value) { | public function setValue($value) { | ||||
| $this->hasValue = true; | $this->hasValue = true; | ||||
| $this->value = $value; | $this->value = $value; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 193 Lines • Show Last 20 Lines | |||||