1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\CoreBundle\Form; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Form\AbstractType; |
6
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
7
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
8
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
9
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
10
|
|
|
use Victoire\Bundle\APIBusinessEntityBundle\Entity\APIBusinessEntity; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Create an entity proxy for the widget.*. |
14
|
|
|
*/ |
15
|
|
|
class AdditionnalPropertiesType extends AbstractType |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* define form fields. |
19
|
|
|
* |
20
|
|
|
* @param FormBuilderInterface $builder |
21
|
|
|
* @param array $options |
22
|
|
|
*/ |
23
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
24
|
|
|
{ |
25
|
|
|
$matches = []; |
26
|
|
|
/** @var APIBusinessEntity $businessEntity */ |
27
|
|
|
$businessEntity = $options['businessEntity']; |
28
|
|
|
$getMethod = $businessEntity->getGetMethod(); |
29
|
|
|
preg_match_all('/{{([a-zA-Z]+)}}/', $getMethod, $matches); |
30
|
|
|
$identifiers = array_map(function ($property) { |
31
|
|
|
return $property->getName(); |
32
|
|
|
}, |
33
|
|
|
$businessEntity->getBusinessIdentifiers()->toArray() |
34
|
|
|
); |
35
|
|
|
foreach ($matches[1] as $match) { |
36
|
|
|
if (!in_array($match, $identifiers)) { |
37
|
|
|
if ($property = $businessEntity->getBusinessPropertyByName($match)) { |
|
|
|
|
38
|
|
|
if (!$property->getChoices() && !$property->getListMethod()) { |
39
|
|
|
$builder->add( |
40
|
|
|
$match, |
41
|
|
|
TextType::class, |
42
|
|
|
[ |
43
|
|
|
'label' => false, |
44
|
|
|
'required' => false, |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
} elseif ($property->getListMethod()) { |
|
|
|
|
48
|
|
|
//TODO |
49
|
|
|
} elseif ($choices = $property->getChoices()) { |
50
|
|
|
$builder->add( |
51
|
|
|
$match, |
52
|
|
|
ChoiceType::class, |
53
|
|
|
[ |
54
|
|
|
'choices' => $choices, |
55
|
|
|
'label' => false, |
56
|
|
|
'required' => false, |
57
|
|
|
] |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* bind to Menu entity. |
67
|
|
|
* |
68
|
|
|
* @param OptionsResolver $resolver |
69
|
|
|
*/ |
70
|
|
|
public function configureOptions(OptionsResolver $resolver) |
71
|
|
|
{ |
72
|
|
|
$resolver->setDefaults( |
73
|
|
|
[ |
74
|
|
|
'businessEntity' => null, |
75
|
|
|
] |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.