diff --git a/src/ArdentParameterBundle.php b/src/ArdentParameterBundle.php index 0129490..4eb260e 100644 --- a/src/ArdentParameterBundle.php +++ b/src/ArdentParameterBundle.php @@ -14,6 +14,7 @@ class ArdentParameterBundle extends AbstractBundle public const TYPE_TEXT = 'text'; public const TYPE_NUMBER = 'number'; public const TYPE_BOOL = 'bool'; + public const TYPE_CHOICE = 'choice'; public function configure(DefinitionConfigurator $definition): void { @@ -21,19 +22,22 @@ class ArdentParameterBundle extends AbstractBundle $definition->rootNode() ->children() - ->arrayNode('parameters') - ->arrayPrototype() - ->arrayPrototype() - ->children() - ->scalarNode('name')->end() - ->enumNode('type') - ->values([self::TYPE_TEXT, self::TYPE_NUMBER, self::TYPE_BOOL]) - ->defaultValue(self::TYPE_TEXT) - ->end() - ->end() - ->end() - ->end() - ->end() + ->arrayNode('parameters') + ->arrayPrototype() + ->arrayPrototype() + ->children() + ->scalarNode('name')->end() + ->enumNode('type') + ->values([self::TYPE_TEXT, self::TYPE_NUMBER, self::TYPE_BOOL, self::TYPE_CHOICE]) + ->defaultValue(self::TYPE_TEXT) + ->end() + ->arrayNode('choices') + ->scalarPrototype()->end() + ->end() + ->end() + ->end() + ->end() + ->end() ->end(); } diff --git a/src/Controller/BaseController.php b/src/Controller/BaseController.php index 773e87d..8c5a9b2 100644 --- a/src/Controller/BaseController.php +++ b/src/Controller/BaseController.php @@ -61,7 +61,7 @@ abstract class BaseController extends AbstractController $options = []; switch ($type) { case ChoiceType::class: - $choices = $config['choices']; + $choices = array_combine($config['choices'], $config['choices']); if (is_callable($choices)) { $options['choices'] = $choices(); diff --git a/src/Service/ParameterService.php b/src/Service/ParameterService.php index 3366bcd..3ddd508 100644 --- a/src/Service/ParameterService.php +++ b/src/Service/ParameterService.php @@ -7,6 +7,7 @@ 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\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -23,6 +24,9 @@ class ParameterService $this->config = $this->supplementConfig($config); } + /** + * @param string $name The name of the parameter in the format _ + */ public function get(string $name, bool $parse = true): mixed { $split = explode('_', $name); @@ -88,6 +92,9 @@ class ParameterService case ArdentParameterBundle::TYPE_BOOL: $class = CheckboxType::class; break; + case ArdentParameterBundle::TYPE_CHOICE: + $class = ChoiceType::class; + break; } // Add the group name in front of the parameter name