Skip to content

Commit

Permalink
Merge pull request #22 from mathroc/master
Browse files Browse the repository at this point in the history
use FQCN form types instead of names
  • Loading branch information
Burgov committed May 31, 2016
2 parents 87ccbe8 + 3687a07 commit 2810ccb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Form/Type/KeyValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Burgov\Bundle\KeyValueFormBundle\Form\DataTransformer\HashToKeyValueArrayTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
Expand Down Expand Up @@ -48,10 +49,10 @@ public function configureOptions(OptionsResolver $resolver)
$isSf28 = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');

$resolver->setDefaults(array(
$isSf28 ? 'entry_type' : 'type' => 'burgov_key_value_row',
$isSf28 ? 'entry_type' : 'type' => $isSf28 ? KeyValueRowType::class : 'burgov_key_value_row',
'allow_add' => true,
'allow_delete' => true,
'key_type' => 'text',
'key_type' => $isSf28 ? TextType::class : 'text',
'key_options' => array(),
'value_options' => array(),
'allowed_keys' => null,
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ public function registerBundles()
Usage
-----

To add to your form, use the alias `burgov_key_value`:
To add to your form, use the `KeyValueType` type:

```php
$builder->add('parameters', 'burgov_key_value', array('value_type' => 'text'));
use Burgov\Bundle\KeyValueFormBundle\Form\Type\KeyValueType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

$builder->add('parameters', KeyValueType::class, array('value_type' => TextType::class));

// or

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

The type extends the collection type, so for rendering it in the browser, the same logic is used. See the
Expand All @@ -53,7 +56,7 @@ The type adds four options to the collection type options, of which one is requi
* `use_container_object` see 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 `burgov_key_value_row` and `allow_add` and `allow_delete` are always `true`.
`type` is set to `BurgovKeyValueRow::class` and `allow_add` and `allow_delete` are always `true`.

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

0 comments on commit 2810ccb

Please sign in to comment.