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 $initialValue; | |||||
| 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 $isRequired; | private $isRequired; | ||||
| ▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | abstract class PhabricatorEditField extends Phobject { | ||||
| } | } | ||||
| 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->initialValue = $value; | |||||
| $this->value = $value; | $this->value = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function generateTransaction( | public function generateTransaction( | ||||
| PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
| if (!$this->getTransactionType()) { | if (!$this->getTransactionType()) { | ||||
| Show All 11 Lines | public function generateTransaction( | ||||
| return $xaction; | return $xaction; | ||||
| } | } | ||||
| public function setMetadataValue($key, $value) { | public function setMetadataValue($key, $value) { | ||||
| $this->metadata[$key] = $value; | $this->metadata[$key] = $value; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getMetadata() { | |||||
| return $this->metadata; | |||||
| } | |||||
| protected function getValueForTransaction() { | protected function getValueForTransaction() { | ||||
| return $this->getValue(); | return $this->getValue(); | ||||
| } | } | ||||
| public function getTransactionType() { | public function getTransactionType() { | ||||
| return $this->transactionType; | return $this->transactionType; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | abstract class PhabricatorEditField extends Phobject { | ||||
| protected function getValueExistsInRequest(AphrontRequest $request, $key) { | protected function getValueExistsInRequest(AphrontRequest $request, $key) { | ||||
| return $this->getValueExistsInSubmit($request, $key); | return $this->getValueExistsInSubmit($request, $key); | ||||
| } | } | ||||
| protected function getValueFromRequest(AphrontRequest $request, $key) { | protected function getValueFromRequest(AphrontRequest $request, $key) { | ||||
| return $this->getValueFromSubmit($request, $key); | return $this->getValueFromSubmit($request, $key); | ||||
| } | } | ||||
| /** | |||||
| * Read and return the value the object had when the user first loaded the | |||||
| * form. | |||||
| * | |||||
| * This is the initial value from the user's point of view when they started | |||||
| * the edit process, and used primarily to prevent race conditions for fields | |||||
| * like "Projects" and "Subscribers" that use tokenizers and support edge | |||||
| * transactions. | |||||
| * | |||||
| * Most fields do not need to store these values or deal with initial value | |||||
| * handling. | |||||
| * | |||||
| * @param AphrontRequest Request to read from. | |||||
| * @param string Key to read. | |||||
| * @return wild Value read from request. | |||||
| */ | |||||
| protected function getInitialValueFromSubmit(AphrontRequest $request, $key) { | |||||
| return null; | |||||
| } | |||||
| public function getInitialValue() { | |||||
| return $this->initialValue; | |||||
| } | |||||
| public function readValueFromSubmit(AphrontRequest $request) { | public function readValueFromSubmit(AphrontRequest $request) { | ||||
| $key = $this->getKey(); | $key = $this->getKey(); | ||||
| if ($this->getValueExistsInSubmit($request, $key)) { | if ($this->getValueExistsInSubmit($request, $key)) { | ||||
| $value = $this->getValueFromSubmit($request, $key); | $value = $this->getValueFromSubmit($request, $key); | ||||
| } else { | } else { | ||||
| $value = $this->getDefaultValue(); | $value = $this->getDefaultValue(); | ||||
| } | } | ||||
| $this->value = $value; | $this->value = $value; | ||||
| $initial_value = $this->getInitialValueFromSubmit($request, $key); | |||||
| $this->initialValue = $initial_value; | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function getValueExistsInSubmit(AphrontRequest $request, $key) { | protected function getValueExistsInSubmit(AphrontRequest $request, $key) { | ||||
| $type = $this->getHTTPParameterType(); | $type = $this->getHTTPParameterType(); | ||||
| if ($type) { | if ($type) { | ||||
| return $type->getExists($request, $key); | return $type->getExists($request, $key); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public function getEditTypeKey() { | ||||
| return $this->editTypeKey; | return $this->editTypeKey; | ||||
| } | } | ||||
| protected function newEditType() { | protected function newEditType() { | ||||
| return id(new PhabricatorSimpleEditType()) | return id(new PhabricatorSimpleEditType()) | ||||
| ->setValueType($this->getHTTPParameterType()->getTypeName()); | ->setValueType($this->getHTTPParameterType()->getTypeName()); | ||||
| } | } | ||||
| public function getEditTransactionTypes() { | protected function getEditTransactionType() { | ||||
| $transaction_type = $this->getTransactionType(); | $transaction_type = $this->getTransactionType(); | ||||
| if ($transaction_type === null) { | if ($transaction_type === null) { | ||||
| return array(); | return null; | ||||
| } | } | ||||
| $type_key = $this->getEditTypeKey(); | $type_key = $this->getEditTypeKey(); | ||||
| // TODO: This is a pretty big pile of hard-coded hacks for now. | return $this->newEditType() | ||||
| ->setEditType($type_key) | |||||
| $edge_types = array( | |||||
| PhabricatorTransactions::TYPE_EDGE => array( | |||||
| '+' => pht('Add projects.'), | |||||
| '-' => pht('Remove projects.'), | |||||
| '=' => pht('Set associated projects, overwriting current value.'), | |||||
| ), | |||||
| PhabricatorTransactions::TYPE_SUBSCRIBERS => array( | |||||
| '+' => pht('Add subscribers.'), | |||||
| '-' => pht('Remove subscribers.'), | |||||
| '=' => pht('Set subscribers, overwriting current value.'), | |||||
| ), | |||||
| ); | |||||
| if (isset($edge_types[$transaction_type])) { | |||||
| $base = id(new PhabricatorEdgeEditType()) | |||||
| ->setTransactionType($transaction_type) | ->setTransactionType($transaction_type) | ||||
| ->setMetadata($this->metadata); | ->setDescription($this->getDescription()) | ||||
| ->setMetadata($this->getMetadata()); | |||||
| } | |||||
| $strings = $edge_types[$transaction_type]; | public function getEditTransactionTypes() { | ||||
| $edit_type = $this->getEditTransactionType(); | |||||
| $add = id(clone $base) | if ($edit_type === null) { | ||||
| ->setEditType($type_key.'.add') | return null; | ||||
| ->setEdgeOperation('+') | |||||
| ->setDescription($strings['+']) | |||||
| ->setValueDescription(pht('List of PHIDs to add.')); | |||||
| $rem = id(clone $base) | |||||
| ->setEditType($type_key.'.remove') | |||||
| ->setEdgeOperation('-') | |||||
| ->setDescription($strings['-']) | |||||
| ->setValueDescription(pht('List of PHIDs to remove.')); | |||||
| $set = id(clone $base) | |||||
| ->setEditType($type_key.'.set') | |||||
| ->setEdgeOperation('=') | |||||
| ->setDescription($strings['=']) | |||||
| ->setValueDescription(pht('List of PHIDs to set.')); | |||||
| return array( | |||||
| $add, | |||||
| $rem, | |||||
| $set, | |||||
| ); | |||||
| } | } | ||||
| return array( | return array($edit_type); | ||||
| $this->newEditType() | |||||
| ->setEditType($type_key) | |||||
| ->setTransactionType($transaction_type) | |||||
| ->setDescription($this->getDescription()) | |||||
| ->setMetadata($this->metadata), | |||||
| ); | |||||
| } | } | ||||
| } | } | ||||