Differential D14509 Diff 35177 src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/storage/PhabricatorEditEngineConfiguration.php
| Show All 11 Lines | final class PhabricatorEditEngineConfiguration | ||||
| protected $viewPolicy; | protected $viewPolicy; | ||||
| protected $editPolicy; | protected $editPolicy; | ||||
| protected $properties = array(); | protected $properties = array(); | ||||
| protected $isDisabled = 0; | protected $isDisabled = 0; | ||||
| protected $isDefault = 0; | protected $isDefault = 0; | ||||
| private $engine = self::ATTACHABLE; | private $engine = self::ATTACHABLE; | ||||
| const LOCK_VISIBLE = 'visible'; | |||||
| const LOCK_LOCKED = 'locked'; | |||||
| const LOCK_HIDDEN = 'hidden'; | |||||
| public function getTableName() { | public function getTableName() { | ||||
| return 'search_editengineconfiguration'; | return 'search_editengineconfiguration'; | ||||
| } | } | ||||
| public static function initializeNewConfiguration( | public static function initializeNewConfiguration( | ||||
| PhabricatorUser $actor, | PhabricatorUser $actor, | ||||
| PhabricatorEditEngine $engine) { | PhabricatorEditEngine $engine) { | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public function applyConfigurationToFields( | ||||
| foreach ($fields as $key => $field) { | foreach ($fields as $key => $field) { | ||||
| if ($engine->getIsCreate()) { | if ($engine->getIsCreate()) { | ||||
| if (array_key_exists($key, $values)) { | if (array_key_exists($key, $values)) { | ||||
| $field->readDefaultValueFromConfiguration($values[$key]); | $field->readDefaultValueFromConfiguration($values[$key]); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $locks = $this->getFieldLocks(); | |||||
| foreach ($fields as $field) { | |||||
| $key = $field->getKey(); | |||||
| switch (idx($locks, $key)) { | |||||
| case self::LOCK_LOCKED: | |||||
| $field->setIsLocked(true); | |||||
| break; | |||||
| case self::LOCK_HIDDEN: | |||||
| $field->setIsHidden(true); | |||||
| break; | |||||
| case self::LOCK_VISIBLE: | |||||
| default: | |||||
| break; | |||||
| } | |||||
| } | |||||
| $fields = $this->reorderFields($fields); | $fields = $this->reorderFields($fields); | ||||
| $preamble = $this->getPreamble(); | $preamble = $this->getPreamble(); | ||||
| if (strlen($preamble)) { | if (strlen($preamble)) { | ||||
| $fields = array( | $fields = array( | ||||
| 'config.preamble' => id(new PhabricatorInstructionsEditField()) | 'config.preamble' => id(new PhabricatorInstructionsEditField()) | ||||
| ->setKey('config.preamble') | ->setKey('config.preamble') | ||||
| ->setIsReorderable(false) | ->setIsReorderable(false) | ||||
| ->setIsDefaultable(false) | ->setIsDefaultable(false) | ||||
| ->setIsLockable(false) | |||||
| ->setValue($preamble), | ->setValue($preamble), | ||||
| ) + $fields; | ) + $fields; | ||||
| } | } | ||||
| return $fields; | return $fields; | ||||
| } | } | ||||
| private function reorderFields(array $fields) { | private function reorderFields(array $fields) { | ||||
| $keys = $this->getFieldOrder(); | $keys = $this->getFieldOrder(); | ||||
| $fields = array_select_keys($fields, $keys) + $fields; | $fields = array_select_keys($fields, $keys) + $fields; | ||||
| return $fields; | |||||
| // Now, move locked fields to the bottom. | |||||
| $head = array(); | |||||
| $tail = array(); | |||||
| foreach ($fields as $key => $field) { | |||||
| if (!$field->getIsLocked()) { | |||||
| $head[$key] = $field; | |||||
| } else { | |||||
| $tail[$key] = $field; | |||||
| } | |||||
| } | |||||
| return $head + $tail; | |||||
| } | } | ||||
| public function getURI() { | public function getURI() { | ||||
| $engine_key = $this->getEngineKey(); | $engine_key = $this->getEngineKey(); | ||||
| $key = $this->getIdentifier(); | $key = $this->getIdentifier(); | ||||
| return "/transactions/editengine/{$engine_key}/view/{$key}/"; | return "/transactions/editengine/{$engine_key}/view/{$key}/"; | ||||
| } | } | ||||
| Show All 31 Lines | final class PhabricatorEditEngineConfiguration | ||||
| public function setFieldOrder(array $field_order) { | public function setFieldOrder(array $field_order) { | ||||
| return $this->setProperty('order', $field_order); | return $this->setProperty('order', $field_order); | ||||
| } | } | ||||
| public function getFieldOrder() { | public function getFieldOrder() { | ||||
| return $this->getProperty('order', array()); | return $this->getProperty('order', array()); | ||||
| } | } | ||||
| public function setFieldLocks(array $field_locks) { | |||||
| return $this->setProperty('locks', $field_locks); | |||||
| } | |||||
| public function getFieldLocks() { | |||||
| return $this->getProperty('locks', array()); | |||||
| } | |||||
| public function getFieldDefault($key) { | public function getFieldDefault($key) { | ||||
| $defaults = $this->getProperty('defaults', array()); | $defaults = $this->getProperty('defaults', array()); | ||||
| return idx($defaults, $key); | return idx($defaults, $key); | ||||
| } | } | ||||
| public function setFieldDefault($key, $value) { | public function setFieldDefault($key, $value) { | ||||
| $defaults = $this->getProperty('defaults', array()); | $defaults = $this->getProperty('defaults', array()); | ||||
| $defaults[$key] = $value; | $defaults[$key] = $value; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||