Skip to content

Commit 2810ccb

Browse files
committed
Merge pull request #22 from mathroc/master
use FQCN form types instead of names
2 parents 87ccbe8 + 3687a07 commit 2810ccb

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Form/Type/KeyValueType.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Burgov\Bundle\KeyValueFormBundle\Form\DataTransformer\HashToKeyValueArrayTransformer;
66
use Symfony\Component\Form\AbstractType;
7+
use Symfony\Component\Form\Extension\Core\Type\TextType;
78
use Symfony\Component\Form\FormBuilderInterface;
89
use Symfony\Component\Form\FormEvent;
910
use Symfony\Component\Form\FormEvents;
@@ -48,10 +49,10 @@ public function configureOptions(OptionsResolver $resolver)
4849
$isSf28 = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
4950

5051
$resolver->setDefaults(array(
51-
$isSf28 ? 'entry_type' : 'type' => 'burgov_key_value_row',
52+
$isSf28 ? 'entry_type' : 'type' => $isSf28 ? KeyValueRowType::class : 'burgov_key_value_row',
5253
'allow_add' => true,
5354
'allow_delete' => true,
54-
'key_type' => 'text',
55+
'key_type' => $isSf28 ? TextType::class : 'text',
5556
'key_options' => array(),
5657
'value_options' => array(),
5758
'allowed_keys' => null,

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ public function registerBundles()
2929
Usage
3030
-----
3131

32-
To add to your form, use the alias `burgov_key_value`:
32+
To add to your form, use the `KeyValueType` type:
3333

3434
```php
35-
$builder->add('parameters', 'burgov_key_value', array('value_type' => 'text'));
35+
use Burgov\Bundle\KeyValueFormBundle\Form\Type\KeyValueType;
36+
use Symfony\Component\Form\Extension\Core\Type\TextType;
37+
38+
$builder->add('parameters', KeyValueType::class, array('value_type' => TextType::class));
3639

3740
// or
3841

39-
$formFactory->create('burgov_key_value', $data, array('value_type' => 'text'));
42+
$formFactory->create(KeyValueType::class, $data, array('value_type' => TextType::class));
4043
```
4144

4245
The type extends the collection type, so for rendering it in the browser, the same logic is used. See the
@@ -53,7 +56,7 @@ The type adds four options to the collection type options, of which one is requi
5356
* `use_container_object` see explanation below at 'The KeyValueCollection'
5457

5558
Besides that, this type overrides some defaults of the collection type and it's recommended you don't change them:
56-
`type` is set to `burgov_key_value_row` and `allow_add` and `allow_delete` are always `true`.
59+
`type` is set to `BurgovKeyValueRow::class` and `allow_add` and `allow_delete` are always `true`.
5760

5861
Working with SonataAdminBundle
5962
------------------------------
@@ -93,7 +96,7 @@ it, you need to set the `use_container_object` option on the form type to
9396
/** @var $builder Symfony\Component\Form\FormBuilderInterface */
9497
$builder->add('options', 'burgov_key_value', array(
9598
'required' => false,
96-
'value_type' => 'text',
99+
'value_type' => TextType::class,
97100
'use_container_object' => true,
98101
));
99102
```

0 commit comments

Comments
 (0)