|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\DoctrinePHPCRAdminBundle\Form\Type; |
|
15
|
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceList; |
|
17
|
|
|
use Sonata\AdminBundle\Form\DataTransformer\ModelToIdTransformer; |
|
18
|
|
|
use Symfony\Component\Form\AbstractType; |
|
19
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
20
|
|
|
use Symfony\Component\Form\FormInterface; |
|
21
|
|
|
use Symfony\Component\Form\FormView; |
|
22
|
|
|
use Symfony\Component\OptionsResolver\Options; |
|
23
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
24
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
|
25
|
|
|
|
|
26
|
|
|
class TreeModelType extends AbstractType |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var array |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $defaults = []; |
|
32
|
|
|
|
|
33
|
|
|
public function setDefaults(array $defaults): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->defaults = $defaults; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
42
|
|
|
{ |
|
43
|
|
|
$builder->addViewTransformer(new ModelToIdTransformer($options['model_manager'], $options['class']), true); |
|
44
|
|
|
$builder->setAttribute('root_node', $options['root_node']); |
|
45
|
|
|
$builder->setAttribute('select_root_node', $options['select_root_node']); |
|
46
|
|
|
$builder->setAttribute('repository_name', $options['repository_name']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options): void |
|
53
|
|
|
{ |
|
54
|
|
|
$view->vars['root_node'] = $form->getConfig()->getAttribute('root_node'); |
|
55
|
|
|
$view->vars['select_root_node'] = $form->getConfig()->getAttribute('select_root_node'); |
|
56
|
|
|
$view->vars['repository_name'] = $form->getConfig()->getAttribute('repository_name'); |
|
57
|
|
|
$view->vars['routing_defaults'] = $this->defaults; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* NEXT_MAJOR: remove this method. |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setDefaultOptions(OptionsResolverInterface $resolver): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->configureOptions($resolver); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
|
72
|
|
|
{ |
|
73
|
|
|
$resolver->setDefaults([ |
|
74
|
|
|
'template' => 'doctrine_phpcr_odm_tree', |
|
75
|
|
|
'compound' => false, |
|
76
|
|
|
'model_manager' => null, |
|
77
|
|
|
'class' => null, |
|
78
|
|
|
'property' => null, |
|
79
|
|
|
'query' => null, |
|
80
|
|
|
'choices' => null, |
|
81
|
|
|
'root_node' => '/', |
|
82
|
|
|
'select_root_node' => false, |
|
83
|
|
|
'parent' => 'choice', |
|
84
|
|
|
'repository_name' => 'default', |
|
85
|
|
|
'preferred_choices' => [], |
|
86
|
|
|
'choice_list' => static function (Options $options, $previousValue) { |
|
|
|
|
|
|
87
|
|
|
return new ModelChoiceList( |
|
|
|
|
|
|
88
|
|
|
$options['model_manager'], |
|
89
|
|
|
$options['class'], |
|
90
|
|
|
$options['property'], |
|
91
|
|
|
$options['query'], |
|
92
|
|
|
$options['choices'] |
|
93
|
|
|
); |
|
94
|
|
|
}, |
|
95
|
|
|
]); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* NEXT_MAJOR: remove this method. |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getName() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->getBlockPrefix(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* {@inheritdoc} |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getBlockPrefix() |
|
110
|
|
|
{ |
|
111
|
|
|
return 'doctrine_phpcr_odm_tree'; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
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: