Skip to content

Commit

Permalink
Merge pull request #24 from lulco/lulco/available_values
Browse files Browse the repository at this point in the history
Available values changes
  • Loading branch information
tomaj committed Mar 21, 2016
2 parents 9a1fcc1 + 69637a5 commit 2870b84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Component/ApiConsoleControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,23 @@ protected function createComponentConsoleForm()
if ($param->isMulti()) {
$key = $key . '___' . $i;
}

if ($param->getType() == InputParam::TYPE_FILE) {

if ($param->getAvailableValues() && is_array($param->getAvailableValues())) {
$c = $form->addSelect($key, $this->getParamLabel($param), array_combine($param->getAvailableValues(), $param->getAvailableValues()));
if (!$param->isRequired()) {
$c->setPrompt('Select ' . $this->getLabel($param));
}
} elseif ($param->getAvailableValues() && is_string($param->getAvailableValues())) {
$c = $form->addText($key, $this->getParamLabel($param))->setDisabled(true);
$defaults[$key] = $param->getAvailableValues();
} elseif ($param->getType() == InputParam::TYPE_FILE) {
$c = $form->addUpload($key, $this->getParamLabel($param));
} elseif ($param->getType() == InputParam::TYPE_POST_RAW) {
$c = $form->addTextArea('post_raw', $this->getParamLabel($param))
->setAttribute('rows', 10);
} else {
$c = $form->addText($key, $this->getParamLabel($param));
}

if ($param->getAvailableValues()) {
$c->setOption('description', 'available values: ' . implode(' | ', $param->getAvailableValues()));
}
}
}

Expand All @@ -108,9 +112,14 @@ protected function createComponentConsoleForm()
return $form;
}

private function getLabel(InputParam $param)
{
return ucfirst(str_replace('_', ' ', $param->getKey()));
}

private function getParamLabel(InputParam $param)
{
$title = ucfirst(str_replace('_', ' ', $param->getKey()));
$title = $this->getLabel($param);
if ($param->isRequired()) {
$title .= ' *';
}
Expand Down
4 changes: 4 additions & 0 deletions src/Params/InputParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public function isMulti()
*/
public function isValid()
{
if ($this->required == self::OPTIONAL) {
return true;
}

$value = $this->getValue();
if ($this->availableValues !== null) {
if (is_array($this->availableValues)) {
Expand Down

0 comments on commit 2870b84

Please sign in to comment.