Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editfield/PhabricatorEditField.php
| <?php | <?php | ||||
| abstract class PhabricatorEditField extends Phobject { | abstract class PhabricatorEditField extends Phobject { | ||||
| private $key; | private $key; | ||||
| private $viewer; | private $viewer; | ||||
| private $label; | private $label; | ||||
| private $aliases = array(); | private $aliases = array(); | ||||
| private $value; | private $value; | ||||
| private $hasValue = false; | private $hasValue = false; | ||||
| 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 $isHidden; | |||||
| private $isPreview; | private $isPreview; | ||||
| private $isReorderable = true; | |||||
| private $isEditDefaults; | private $isEditDefaults; | ||||
| private $isReorderable = true; | |||||
| private $isDefaultable = true; | private $isDefaultable = true; | ||||
| private $isLockable = 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 84 Lines • ▼ Show 20 Lines | public function setIsDefaultable($is_defaultable) { | ||||
| $this->isDefaultable = $is_defaultable; | $this->isDefaultable = $is_defaultable; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getIsDefaultable() { | public function getIsDefaultable() { | ||||
| return $this->isDefaultable; | return $this->isDefaultable; | ||||
| } | } | ||||
| public function setIsLockable($is_lockable) { | |||||
| $this->isLockable = $is_lockable; | |||||
| return $this; | |||||
| } | |||||
| public function getIsLockable() { | |||||
| return $this->isLockable; | |||||
| } | |||||
| public function setIsHidden($is_hidden) { | |||||
| $this->isHidden = $is_hidden; | |||||
| return $this; | |||||
| } | |||||
| public function getIsHidden() { | |||||
| return $this->isHidden; | |||||
| } | |||||
| 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->getIsPreview()) { | if ($this->getIsPreview()) { | ||||
| $disabled = true; | $disabled = true; | ||||
| $hidden = false; | |||||
| } else if ($this->getIsEditDefaults()) { | } else if ($this->getIsEditDefaults()) { | ||||
| $disabled = false; | $disabled = false; | ||||
| $hidden = false; | |||||
| } else { | } else { | ||||
| $disabled = $this->getIsLocked(); | $disabled = $this->getIsLocked(); | ||||
| $hidden = $this->getIsHidden(); | |||||
| } | |||||
| if ($hidden) { | |||||
| return null; | |||||
| } | } | ||||
| $control->setDisabled($disabled); | $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) { | ||||
| if ($this->getIsPreview()) { | |||||
| if ($this->getIsHidden()) { | |||||
| $control | |||||
| ->addClass('aphront-form-preview-hidden') | |||||
| ->setError(pht('Hidden')); | |||||
| } else if ($this->getIsLocked()) { | |||||
| $control | |||||
| ->setError(pht('Locked')); | |||||
| } | |||||
| } | |||||
| $form->appendControl($control); | $form->appendControl($control); | ||||
| } | } | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getValueForControl() { | protected function getValueForControl() { | ||||
| return $this->getValue(); | return $this->getValue(); | ||||
| } | } | ||||
| Show All 19 Lines | public function setValue($value) { | ||||
| $this->hasValue = true; | $this->hasValue = true; | ||||
| $this->value = $value; | $this->value = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function generateTransaction( | public function generateTransaction( | ||||
| PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
| if (!$this->getTransactionType()) { | |||||
| return null; | |||||
| } | |||||
| $xaction | $xaction | ||||
| ->setTransactionType($this->getTransactionType()) | ->setTransactionType($this->getTransactionType()) | ||||
| ->setNewValue($this->getValueForTransaction()); | ->setNewValue($this->getValueForTransaction()); | ||||
| foreach ($this->metadata as $key => $value) { | foreach ($this->metadata as $key => $value) { | ||||
| $xaction->setMetadataValue($key, $value); | $xaction->setMetadataValue($key, $value); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 180 Lines • Show Last 20 Lines | |||||