Add support for checkboxtype (booleans)
This commit is contained in:
parent
301862589b
commit
03b561ab1d
@ -4,6 +4,7 @@ namespace App\Ardent\ParameterBundle\Controller;
|
||||
|
||||
use App\Ardent\ParameterBundle\Service\ParameterService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@ -22,7 +23,7 @@ abstract class BaseController extends AbstractController
|
||||
$data = [];
|
||||
foreach ($configuration as $config) {
|
||||
$name = $config['name'];
|
||||
$data[$name] = $param->get($name, false);
|
||||
$data[$name] = $this->valueParser($config['type'], $param->get($name, false));
|
||||
}
|
||||
|
||||
// build the form
|
||||
@ -39,9 +40,7 @@ abstract class BaseController extends AbstractController
|
||||
|
||||
foreach ($configuration as $config) {
|
||||
$name = $config['name'];
|
||||
if ($result[$name]) {
|
||||
$param->set($name, $result[$name]);
|
||||
}
|
||||
$param->set($name, $result[$name]);
|
||||
}
|
||||
$this->addFlash('success', 'Updating parameters successful');
|
||||
|
||||
@ -53,6 +52,18 @@ abstract class BaseController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function valueParser($type, $value)
|
||||
{
|
||||
switch ($type) {
|
||||
case CheckboxType::class:
|
||||
return boolval($value);
|
||||
break;
|
||||
default:
|
||||
return $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
* @param FormBuilderInterface $formBuilder
|
||||
@ -65,6 +76,9 @@ abstract class BaseController extends AbstractController
|
||||
case ChoiceType::class:
|
||||
$options['choices'] = $config['choices'];
|
||||
break;
|
||||
case CheckboxType::class:
|
||||
$options['required'] = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user