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_TEXT = 'text';
|
||||||
public const TYPE_NUMBER = 'number';
|
public const TYPE_NUMBER = 'number';
|
||||||
public const TYPE_BOOL = 'bool';
|
public const TYPE_BOOL = 'bool';
|
||||||
|
public const TYPE_CHOICE = 'choice';
|
||||||
|
|
||||||
public function configure(DefinitionConfigurator $definition): void
|
public function configure(DefinitionConfigurator $definition): void
|
||||||
{
|
{
|
||||||
@ -21,19 +22,22 @@ class ArdentParameterBundle extends AbstractBundle
|
|||||||
|
|
||||||
$definition->rootNode()
|
$definition->rootNode()
|
||||||
->children()
|
->children()
|
||||||
->arrayNode('parameters')
|
->arrayNode('parameters')
|
||||||
->arrayPrototype()
|
->arrayPrototype()
|
||||||
->arrayPrototype()
|
->arrayPrototype()
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('name')->end()
|
->scalarNode('name')->end()
|
||||||
->enumNode('type')
|
->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)
|
->defaultValue(self::TYPE_TEXT)
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->arrayNode('choices')
|
||||||
->end()
|
->scalarPrototype()->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
->end();
|
->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ abstract class BaseController extends AbstractController
|
|||||||
$options = [];
|
$options = [];
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case ChoiceType::class:
|
case ChoiceType::class:
|
||||||
$choices = $config['choices'];
|
$choices = array_combine($config['choices'], $config['choices']);
|
||||||
|
|
||||||
if (is_callable($choices)) {
|
if (is_callable($choices)) {
|
||||||
$options['choices'] = $choices();
|
$options['choices'] = $choices();
|
||||||
|
@ -7,6 +7,7 @@ use Ardent\ParameterBundle\Entity\Parameter;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
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\NumberType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ class ParameterService
|
|||||||
$this->config = $this->supplementConfig($config);
|
$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
|
public function get(string $name, bool $parse = true): mixed
|
||||||
{
|
{
|
||||||
$split = explode('_', $name);
|
$split = explode('_', $name);
|
||||||
@ -88,6 +92,9 @@ class ParameterService
|
|||||||
case ArdentParameterBundle::TYPE_BOOL:
|
case ArdentParameterBundle::TYPE_BOOL:
|
||||||
$class = CheckboxType::class;
|
$class = CheckboxType::class;
|
||||||
break;
|
break;
|
||||||
|
case ArdentParameterBundle::TYPE_CHOICE:
|
||||||
|
$class = ChoiceType::class;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the group name in front of the parameter name
|
// Add the group name in front of the parameter name
|
||||||
|
Loading…
Reference in New Issue
Block a user