A form type for managing key-value pairs.
$ composer require scc/key-value-form-bundleThen add the bundle to your application (bundles.php file):
Scc\KeyValueFormBundle\KeyValueFormBundle::class => ['all' => true],To add to your form, use the KeyValueType type:
use Scc\KeyValueFormBundle\Form\Type\KeyValueType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
$builder->add('parameters', KeyValueType::class, ['value_type' => TextType::class]);
// or
$formFactory->create(KeyValueType::class, $data, ['value_type' => TextType::class]);The type extends the collection type, so for rendering it in the browser, the same logic is used. See the Symfony docs on collection types for an example on how to render it client side.
The type adds four options to the collection type options, of which one is required:
value_type(required) defines which form type to use to render the value fieldvalue_optionsoptional options to the child defined invalue_typekey_typedefines which form type to use to render the key field (default is atextfield)key_optionsoptional options to the child defined inkey_typeallowed_keysif this option is provided, the key field (which is usually a simple text field) will change to achoicefield, and allow only those values you supplied in the this option.use_container_objectsee explanation below at 'The KeyValueCollection'
Besides that, this type overrides some defaults of the collection type and it's recommended you don't change them:
type is set to BurgovKeyValueRow::class and allow_add and allow_delete are always true.