1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GGGGino\SkuskuCartBundle\Form\Type; |
4
|
|
|
|
5
|
|
|
use GGGGino\SkuskuCartBundle\Model\SkuskuCartProductInterface; |
6
|
|
|
use Symfony\Component\Form\AbstractType; |
7
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ButtonType; |
8
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
9
|
|
|
use Symfony\Component\Form\Extension\Core\Type\MoneyType; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
11
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
14
|
|
|
use Symfony\Component\Form\FormEvent; |
15
|
|
|
use Symfony\Component\Form\FormEvents; |
16
|
|
|
use Symfony\Component\Form\FormInterface; |
17
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
18
|
|
|
|
19
|
|
|
class AdditionalFieldsType extends AbstractType |
20
|
|
|
{ |
21
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
foreach ($options['fields'] as $field) { |
25
|
|
|
$class = 'Symfony\Component\Form\Extension\Core\Type\\'.$field['type'] .'Type'; |
26
|
|
|
|
27
|
|
|
$cssClass = null !== $field['class'] ? $field['class'] : ''; |
28
|
|
|
|
29
|
|
|
$builder |
30
|
|
|
->add($field['id'], $class, array( |
31
|
|
|
'label' => $field['label'], |
32
|
|
|
'required' => $field['required'], |
33
|
|
|
'attr' => array( |
34
|
|
|
'class' => $cssClass |
35
|
|
|
) |
36
|
|
|
)); |
37
|
|
|
|
38
|
|
|
if($field['data'] !== null) { |
39
|
|
|
$builder->get($field['id'])->setData( true ); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function configureOptions(OptionsResolver $resolver) |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
$resolver->setDefaults(array( |
49
|
|
|
'fields' => array(), |
50
|
|
|
'label' => false, |
51
|
|
|
'class' => false, |
52
|
|
|
'required' => true, |
53
|
|
|
'data' => null, |
54
|
|
|
)); |
55
|
|
|
} |
56
|
|
|
} |