Skip to content

Commit

Permalink
Valid param always when is not required - also when available values …
Browse files Browse the repository at this point in the history
…are set

Changed rendering in API console when available values are set
  • Loading branch information
lulco committed Mar 20, 2016
1 parent 9a1fcc1 commit 69637a5
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 69637a5

Please sign in to comment.