create a Custom Form Field Type with json_array

1,671 views
Skip to first unread message

13

unread,
Apr 11, 2016, 9:24:47 AM4/11/16
to sonata-users
Hi,

How can I create a Custom Form Field Type with json_array.
I just want to save a couple of information.

Ex :


["key":"78915547","secret_key":"75845", "public_key":"78945"...]


Admin Class:
protected function configureFormFields(FormMapper $formMapper) {
               $formMapper
->add('extra_params', 'extra_param_collection', array(
                   
'allow_add' => true,
               
))...


Custom Form Type :


<?php

namespace Application\Sonata\UserBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface;

class ExtraParamCollectionType extends AbstractType {

 
public function getParent() {
 
return 'collection';
 
}

 
public function getName() {
 
return 'extra_param_collection';
 
}
}


Service :

 extra_param_collection:
 
class: Application\Sonata\UserBundle\Form\Type\ExtraParamCollectionType
 tags
:
 
- { name: form.type }

Entity:
/**
 * @var string
 *
 * @ORM\Column(type="json_array", length=512, nullable=true)
 */

 
private $extra_params;


How i can display in my form many fields and how to save it in this format?

Thank you in advance


13

unread,
Apr 14, 2016, 9:54:38 AM4/14/16
to sonata-users
Found :

https://github.com/Burgov/KeyValueFormBundle

Exactly what I need :)
Reply all
Reply to author
Forward
0 new messages