Differential D18156 Diff 43702 src/applications/config/controller/PhabricatorConfigEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/controller/PhabricatorConfigEditController.php
Show First 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | if ($type) { | ||||
if ($is_set) { | if ($is_set) { | ||||
$value = $type->readValueFromRequest($option, $request); | $value = $type->readValueFromRequest($option, $request); | ||||
$errors = array(); | $errors = array(); | ||||
try { | try { | ||||
$canonical_value = $type->newValueFromRequestValue( | $canonical_value = $type->newValueFromRequestValue( | ||||
$option, | $option, | ||||
$value); | $value); | ||||
$type->validateStoredValue($canonical_value); | $type->validateStoredValue($option, $canonical_value); | ||||
$xaction = $type->newTransaction($option, $canonical_value); | $xaction = $type->newTransaction($option, $canonical_value); | ||||
} catch (PhabricatorConfigValidationException $ex) { | } catch (PhabricatorConfigValidationException $ex) { | ||||
$errors[] = $ex->getMessage(); | $errors[] = $ex->getMessage(); | ||||
$xaction = null; | $xaction = null; | ||||
} | } | ||||
return array( | return array( | ||||
$errors ? pht('Invalid') : null, | $errors ? pht('Invalid') : null, | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if ($option->isCustomType()) { | ||||
return array($e_value, $errors, $value, $xaction); | return array($e_value, $errors, $value, $xaction); | ||||
} | } | ||||
$type = $option->getType(); | $type = $option->getType(); | ||||
$set_value = null; | $set_value = null; | ||||
switch ($type) { | switch ($type) { | ||||
case 'string': | |||||
case 'enum': | |||||
$set_value = (string)$value; | |||||
break; | |||||
case 'list<string>': | case 'list<string>': | ||||
case 'list<regex>': | case 'list<regex>': | ||||
$set_value = phutil_split_lines( | $set_value = phutil_split_lines( | ||||
$request->getStr('value'), | $request->getStr('value'), | ||||
$retain_endings = false); | $retain_endings = false); | ||||
foreach ($set_value as $key => $v) { | foreach ($set_value as $key => $v) { | ||||
if (!strlen($v)) { | if (!strlen($v)) { | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | private function getDisplayValue( | ||||
if ($option->isCustomType()) { | if ($option->isCustomType()) { | ||||
return $option->getCustomObject()->getDisplayValue( | return $option->getCustomObject()->getDisplayValue( | ||||
$option, | $option, | ||||
$entry, | $entry, | ||||
$value); | $value); | ||||
} else { | } else { | ||||
$type = $option->getType(); | $type = $option->getType(); | ||||
switch ($type) { | switch ($type) { | ||||
case 'string': | |||||
case 'enum': | |||||
case 'class': | case 'class': | ||||
return $value; | return $value; | ||||
case 'bool': | case 'bool': | ||||
return $value ? 'true' : 'false'; | return $value ? 'true' : 'false'; | ||||
case 'list<string>': | case 'list<string>': | ||||
case 'list<regex>': | case 'list<regex>': | ||||
return implode("\n", nonempty($value, array())); | return implode("\n", nonempty($value, array())); | ||||
case 'set': | case 'set': | ||||
Show All 20 Lines | private function renderControls( | ||||
if ($option->isCustomType()) { | if ($option->isCustomType()) { | ||||
$controls = $option->getCustomObject()->renderControls( | $controls = $option->getCustomObject()->renderControls( | ||||
$option, | $option, | ||||
$display_value, | $display_value, | ||||
$e_value); | $e_value); | ||||
} else { | } else { | ||||
$type = $option->getType(); | $type = $option->getType(); | ||||
switch ($type) { | switch ($type) { | ||||
case 'string': | |||||
$control = id(new AphrontFormTextControl()); | |||||
break; | |||||
case 'bool': | case 'bool': | ||||
$control = id(new AphrontFormSelectControl()) | $control = id(new AphrontFormSelectControl()) | ||||
->setOptions( | ->setOptions( | ||||
array( | array( | ||||
'' => pht('(Use Default)'), | '' => pht('(Use Default)'), | ||||
'true' => idx($option->getBoolOptions(), 0), | 'true' => idx($option->getBoolOptions(), 0), | ||||
'false' => idx($option->getBoolOptions(), 1), | 'false' => idx($option->getBoolOptions(), 1), | ||||
)); | )); | ||||
break; | break; | ||||
case 'enum': | |||||
$options = array_mergev( | |||||
array( | |||||
array('' => pht('(Use Default)')), | |||||
$option->getEnumOptions(), | |||||
)); | |||||
$control = id(new AphrontFormSelectControl()) | |||||
->setOptions($options); | |||||
break; | |||||
case 'class': | case 'class': | ||||
$symbols = id(new PhutilSymbolLoader()) | $symbols = id(new PhutilSymbolLoader()) | ||||
->setType('class') | ->setType('class') | ||||
->setAncestorClass($option->getBaseClass()) | ->setAncestorClass($option->getBaseClass()) | ||||
->setConcreteOnly(true) | ->setConcreteOnly(true) | ||||
->selectSymbolsWithoutLoading(); | ->selectSymbolsWithoutLoading(); | ||||
$names = ipull($symbols, 'name', 'name'); | $names = ipull($symbols, 'name', 'name'); | ||||
asort($names); | asort($names); | ||||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |