Skip to content

Commit 2464e6b

Browse files
authored
Merge pull request #1 from eliophot-studio/master
SF3 Compatibility
2 parents 00519c5 + 9b939fa commit 2464e6b

15 files changed

+165
-74
lines changed

Form/Extension/FieldTypeHelpExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
4141
}
4242

4343
/**
44-
* @param OptionsResolverInterface $resolver
44+
* @param OptionsResolver $resolver
4545
*/
46-
public function setDefaultOptions(OptionsResolverInterface $resolver)
46+
public function configureOptions(OptionsResolver $resolver)
4747
{
4848
$resolver->setDefaults(array(
4949
'help' => null,
@@ -55,6 +55,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
5555
*/
5656
public function getExtendedType()
5757
{
58-
return 'form';
58+
return FormType::class;
5959
}
60-
}
60+
}

Form/Extension/FieldTypePictoExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
4141
}
4242

4343
/**
44-
* @param OptionsResolverInterface $resolver
44+
* @param OptionsResolver $resolver
4545
*/
46-
public function setDefaultOptions(OptionsResolverInterface $resolver)
46+
public function configureOptions(OptionsResolver $resolver)
4747
{
4848
$resolver->setDefaults(array(
4949
'picto' => null,
@@ -55,6 +55,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
5555
*/
5656
public function getExtendedType()
5757
{
58-
return 'form';
58+
return FormType::class;
5959
}
60-
}
60+
}

Form/Extension/FieldTypePopinExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
4242
}
4343

4444
/**
45-
* @param OptionsResolverInterface $resolver
45+
* @param OptionsResolver $resolver
4646
*/
47-
public function setDefaultOptions(OptionsResolverInterface $resolver)
47+
public function configureOptions(OptionsResolver $resolver)
4848
{
4949
$resolver->setDefaults(array(
5050
'popin' => null,
@@ -56,6 +56,6 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
5656
*/
5757
public function getExtendedType()
5858
{
59-
return 'form';
59+
return FormType::class;
6060
}
61-
}
61+
}

Form/Field/FieldBuilder.php

+46-28
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
*/
2222
class FieldBuilder implements FieldBuilderInterface
2323
{
24+
/**
25+
* @param string $name
26+
* @param string $field
27+
* @param array $options
28+
* @param FormBuilderInterface $builder
29+
*/
2430
public function addField($name, $field, $options, FormBuilderInterface $builder)
2531
{
2632
if (array_key_exists('data', $options) && $field->type == 'genemu_jquerydate') {
@@ -42,34 +48,14 @@ public function addField($name, $field, $options, FormBuilderInterface $builder)
4248
}
4349
}
4450

45-
private function addSingleField($name, $field, $options, $builder)
46-
{
47-
$builder->add($name, $field->type, $options);
48-
}
49-
50-
private function addMultipleField($name, $field, $options, $builder)
51-
{
52-
$builder->add($name, 'collection', array(
53-
'label' => $options['label'],
54-
'error_bubbling' => false,
55-
'type' => new VirtualType($options, $field),
56-
'allow_add' => true,
57-
'allow_delete' => true,
58-
'prototype' => true,
59-
'required' => ($options['required']) ? $options['required'] : false,
60-
'attr' => array('class' => 'prototype'),
61-
'data' =>(array_key_exists('data', $options) && is_array($options['data'])) ? $options['data'] : null
62-
));
63-
}
64-
6551
/**
6652
* Length constraint on multiple field
67-
* @param unknown $formFields
68-
* @param unknown $builder
53+
* @param mixed $formFields
54+
* @param mixed $builder
6955
*/
7056
public function addMultipleFieldPostBindEvent($formFields, $builder)
7157
{
72-
$builder->addEventListener(FormEvents::POST_BIND, function (FormEvent $event) use ($builder, $formFields) {
58+
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($builder, $formFields) {
7359

7460
$form = $event->getForm();
7561

@@ -105,8 +91,8 @@ public function addMultipleFieldPostBindEvent($formFields, $builder)
10591

10692
/**
10793
* Modifies data before they are bound to the form
108-
* @param unknown $formFields
109-
* @param unknown $builder
94+
* @param mixed $formFields
95+
* @param mixed $builder
11096
*/
11197
public function alterDataPreSetDataEvent($formFields, $builder)
11298
{
@@ -129,7 +115,7 @@ public function alterDataPreSetDataEvent($formFields, $builder)
129115
if ($dateTimeValue != false) {
130116
$formData[$name][$subFieldName] = $dateTimeValue;
131117
}
132-
} else if ("fieldset" == $subField->type) {
118+
} elseif ("fieldset" == $subField->type) {
133119
//In case a fieldset contains another fieldset with date - better rewrite with recursive walker
134120
foreach ($subField->attr->subforms as $subSubFieldName => $subSubField) {
135121
if ("date" == $subSubField->type && array_key_exists($name, $formData) && array_key_exists($subFieldName, $formData[$name]) && array_key_exists($subSubFieldName, $formData[$name][$subFieldName])) {
@@ -146,7 +132,7 @@ public function alterDataPreSetDataEvent($formFields, $builder)
146132
}
147133
}
148134
}
149-
} else if ("date" == $field->type) {
135+
} elseif ("date" == $field->type) {
150136
$dateTimeValue = \DateTime::createFromFormat('Y-m-d H:i:s.u', $formData[$name]['date']);
151137
// try to get the date without milliseconds
152138
if (!$dateTimeValue) {
@@ -171,7 +157,7 @@ public function alterDataPreSetDataEvent($formFields, $builder)
171157
*/
172158
public function addAssociatedFielPostBindEvent($formFields, $builder)
173159
{
174-
$builder->addEventListener(FormEvents::POST_BIND, function (FormEvent $event) use ($builder, $formFields) {
160+
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use ($builder, $formFields) {
175161

176162
$form = $event->getForm();
177163

@@ -203,4 +189,36 @@ public function addAssociatedFielPostBindEvent($formFields, $builder)
203189
}
204190
});
205191
}
192+
193+
/**
194+
* @param string $name
195+
* @param \stdClass $field
196+
* @param array $options
197+
* @param FormBuilderInterface $builder
198+
*/
199+
private function addSingleField($name, $field, $options, $builder)
200+
{
201+
$builder->add($name, $field->type, $options);
202+
}
203+
204+
/**
205+
* @param string $name
206+
* @param \stdClass $field
207+
* @param array $options
208+
* @param FormBuilderInterface $builder
209+
*/
210+
private function addMultipleField($name, $field, $options, $builder)
211+
{
212+
$builder->add($name, CollectionType::class, array(
213+
'label' => $options['label'],
214+
'error_bubbling' => false,
215+
'entry_type' => new VirtualType($options, $field),
216+
'allow_add' => true,
217+
'allow_delete' => true,
218+
'prototype' => true,
219+
'required' => ($options['required']) ? $options['required'] : false,
220+
'attr' => array('class' => 'prototype'),
221+
'data' => (array_key_exists('data', $options) && is_array($options['data'])) ? $options['data'] : null,
222+
));
223+
}
206224
}

Form/Field/FieldBuilderInterface.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ interface FieldBuilderInterface
2020
/**
2121
* Add a field to dynamic form
2222
*
23-
* @param $name
24-
* @param string $field
25-
* @param array $options
23+
* @param string $name
24+
* @param string $field
25+
* @param array $options
2626
* @param FormBuilderInterface $builder
2727
* @return mixed
2828
*/
29-
public function addField($name, $field, $options,FormBuilderInterface $builder);
30-
}
29+
public function addField($name, $field, $options, FormBuilderInterface $builder);
30+
}

Form/FormManager.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,33 @@ class FormManager implements FormManagerInterface
2525
protected $formFactory;
2626
protected $dynamicFormType;
2727

28+
/**
29+
* FormManager constructor.
30+
* @param EventDispatcherInterface $dispatcher
31+
* @param FormFactoryInterface $formFactory
32+
* @param mixed $dynamicFormType
33+
*/
2834
public function __construct(EventDispatcherInterface $dispatcher, FormFactoryInterface $formFactory, $dynamicFormType)
2935
{
3036
$this->dispatcher = $dispatcher;
3137
$this->formFactory = $formFactory;
3238
$this->dynamicFormType = $dynamicFormType;
3339
}
3440

41+
/**
42+
* @param FormProviderInterface $formProvider
43+
* @return \Symfony\Component\Form\FormInterface
44+
*/
3545
public function createForm(FormProviderInterface $formProvider)
3646
{
3747
$this->dynamicFormType->setFormStruct($formProvider->buildJson());
3848
$this->dynamicFormType->setFormName($formProvider->getFormName());
39-
$form = $this->formFactory->create($this->dynamicFormType);
49+
50+
$form = $this->formFactory->create(DynamicFormType::class);
4051

4152
$event = new FormEvent($form);
4253
$this->dispatcher->dispatch(Events::FORM_CREATE, $event);
4354

4455
return $form;
4556
}
46-
4757
}

Form/FormManagerInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ interface FormManagerInterface
1919
{
2020
/**
2121
* Creates an empty form instance.
22-
* @param mixed $formStruc
23-
* @return Form
22+
* @param FormProviderInterface $formProvider
23+
* @return mixed
2424
*/
2525
public function createForm(FormProviderInterface $formProvider);
2626
}

Form/Provider/ArrayFormProvider.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,35 @@ class ArrayFormProvider implements FormProviderInterface
1313

1414
private $formName;
1515

16+
/**
17+
* @param array $formArray
18+
*/
1619
public function setFormArray(array $formArray)
1720
{
1821
$this->formArray = $formArray;
1922
}
2023

24+
/**
25+
* @return string
26+
*/
2127
public function buildJson()
2228
{
2329
return json_encode($this->formArray);
2430
}
25-
26-
public function setFormName($formName) {
31+
32+
/**
33+
* @param mixed $formName
34+
*/
35+
public function setFormName($formName)
36+
{
2737
$this->formName = $formName;
2838
}
29-
30-
public function getFormName() {
39+
40+
/**
41+
* @return mixed
42+
*/
43+
public function getFormName()
44+
{
3145
return $this->formName;
3246
}
33-
}
47+
}

Form/Provider/FormProviderInterface.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
namespace ACSEO\Bundle\DynamicFormBundle\Form\Provider;
1212

13+
/**
14+
* Interface FormProviderInterface
15+
* @package ACSEO\Bundle\DynamicFormBundle\Form\Provider
16+
*/
1317
interface FormProviderInterface
1418
{
1519
/**
@@ -21,4 +25,4 @@ public function buildJson();
2125
* Define form name
2226
*/
2327
public function getFormName();
24-
}
28+
}

Form/Type/DynamicFormAbstractType.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@
1818
abstract class DynamicFormAbstractType extends AbstractType
1919
{
2020
protected $formStruct;
21-
21+
2222
protected $formName;
2323

24+
/**
25+
* @param mixed $formStruct
26+
*/
2427
public function setFormStruct($formStruct)
2528
{
2629
$this->formStruct = $formStruct;
2730
}
28-
31+
32+
/**
33+
* @param mixed $formName
34+
*/
2935
public function setFormName($formName)
3036
{
3137
$this->formName = $formName;
3238
}
33-
34-
}
39+
}

0 commit comments

Comments
 (0)