From cd3c5a0a52c055f61f78a5c4e7455749eb0f5f4e Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 30 Jan 2022 01:11:39 +0100 Subject: [PATCH] Allow for bool type as config type --- Controller/BaseController.php | 2 -- DependencyInjection/Configuration.php | 3 ++- Service/ParameterService.php | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Controller/BaseController.php b/Controller/BaseController.php index 237ee45..4b65f51 100644 --- a/Controller/BaseController.php +++ b/Controller/BaseController.php @@ -60,10 +60,8 @@ abstract class BaseController extends AbstractController switch ($type) { case CheckboxType::class: return boolval($value); - break; default: return $value; - break; } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1627a1d..04be94a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -11,6 +11,7 @@ class Configuration implements ConfigurationInterface { public const TYPE_TEXT = 'text'; public const TYPE_NUMBER = 'number'; + public const TYPE_BOOL = 'bool'; public function getConfigTreeBuilder() { @@ -24,7 +25,7 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('name')->end() ->enumNode('type') - ->values([self::TYPE_TEXT, self::TYPE_NUMBER]) + ->values([self::TYPE_TEXT, self::TYPE_NUMBER, self::TYPE_BOOL]) ->defaultValue(self::TYPE_TEXT) ->end() ->end() diff --git a/Service/ParameterService.php b/Service/ParameterService.php index 797440d..50d02b9 100644 --- a/Service/ParameterService.php +++ b/Service/ParameterService.php @@ -6,6 +6,7 @@ use Ardent\ParameterBundle\DependencyInjection\Configuration; use Ardent\ParameterBundle\Entity\Parameter; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -101,6 +102,9 @@ class ParameterService case Configuration::TYPE_NUMBER: $class = NumberType::class; break; + case Configuration::TYPE_BOOL: + $class = CheckboxType::class; + break; } // Add the group name in front of the parameter name