1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\DoctrinePHPCRAdminBundle\Form\Type; |
13
|
|
|
|
14
|
|
|
use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList; |
15
|
|
|
use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer; |
16
|
|
|
use Symfony\Component\Form\AbstractType; |
17
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
18
|
|
|
use Symfony\Component\Form\FormInterface; |
19
|
|
|
use Symfony\Component\Form\FormView; |
20
|
|
|
use Symfony\Component\OptionsResolver\Options; |
21
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
22
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
23
|
|
|
|
24
|
|
|
class TreeModelType extends AbstractType |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $defaults = array(); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array $defaults |
33
|
|
|
*/ |
34
|
|
|
public function setDefaults(array $defaults) |
35
|
|
|
{ |
36
|
|
|
$this->defaults = $defaults; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
43
|
|
|
{ |
44
|
|
|
$builder->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']), true); |
45
|
|
|
$builder->setAttribute('root_node', $options['root_node']); |
46
|
|
|
$builder->setAttribute('select_root_node', $options['select_root_node']); |
47
|
|
|
$builder->setAttribute('repository_name', $options['repository_name']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options) |
54
|
|
|
{ |
55
|
|
|
$view->vars['root_node'] = $form->getConfig()->getAttribute('root_node'); |
56
|
|
|
$view->vars['select_root_node'] = $form->getConfig()->getAttribute('select_root_node'); |
57
|
|
|
$view->vars['repository_name'] = $form->getConfig()->getAttribute('repository_name'); |
58
|
|
|
$view->vars['routing_defaults'] = $this->defaults; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
* |
64
|
|
|
* @todo Remove when Symfony <2.8 is no longer supported |
65
|
|
|
*/ |
66
|
|
|
public function setDefaultOptions(OptionsResolverInterface $resolver) |
67
|
|
|
{ |
68
|
|
|
$this->configureOptions($resolver); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function configureOptions(OptionsResolver $resolver) |
75
|
|
|
{ |
76
|
|
|
$resolver->setDefaults(array( |
77
|
|
|
'template' => 'doctrine_phpcr_odm_tree', |
78
|
|
|
'compound' => false, |
79
|
|
|
'model_manager' => null, |
80
|
|
|
'class' => null, |
81
|
|
|
'property' => null, |
82
|
|
|
'query' => null, |
83
|
|
|
'choices' => null, |
84
|
|
|
'root_node' => '/', |
85
|
|
|
'select_root_node' => false, |
86
|
|
|
'parent' => 'choice', |
87
|
|
|
'repository_name' => 'default', |
88
|
|
|
'preferred_choices' => array(), |
89
|
|
|
'choice_list' => function (Options $options, $previousValue) { |
|
|
|
|
90
|
|
|
return new ModelChoiceList( |
|
|
|
|
91
|
|
|
$options['model_manager'], |
92
|
|
|
$options['class'], |
93
|
|
|
$options['property'], |
94
|
|
|
$options['query'], |
95
|
|
|
$options['choices'] |
96
|
|
|
); |
97
|
|
|
}, |
98
|
|
|
)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
* |
104
|
|
|
* @todo Remove when Symfony <2.8 is no longer supported |
105
|
|
|
*/ |
106
|
|
|
public function getName() |
107
|
|
|
{ |
108
|
|
|
return $this->getBlockPrefix(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
public function getBlockPrefix() |
115
|
|
|
{ |
116
|
|
|
return 'doctrine_phpcr_odm_tree'; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: