Allow choice type in parameter config
This commit is contained in:
parent
7040fd5ea7
commit
61b8a68705
@ -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
|
||||
{
|
||||
@ -27,9 +28,12 @@ class ArdentParameterBundle extends AbstractBundle
|
||||
->children()
|
||||
->scalarNode('name')->end()
|
||||
->enumNode('type')
|
||||
->values([self::TYPE_TEXT, self::TYPE_NUMBER, self::TYPE_BOOL])
|
||||
->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()
|
||||
|
@ -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();
|
||||
|
@ -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 <group>_<parameter>
|
||||
*/
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user