1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[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 Core23\Form\Type; |
13
|
|
|
|
14
|
|
|
use PUGX\AutocompleterBundle\Form\Type\AutocompleteType as BaseAutocompleteType; |
15
|
|
|
use Symfony\Component\Form\AbstractType; |
16
|
|
|
use Symfony\Component\Form\FormInterface; |
17
|
|
|
use Symfony\Component\Form\FormView; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
20
|
|
|
|
21
|
|
|
final class AutocompleteType extends AbstractType |
22
|
|
|
{ |
23
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
24
|
|
|
{ |
25
|
|
|
$resolver |
26
|
|
|
->setDefaults([ |
27
|
|
|
'property' => null, |
28
|
|
|
'empty_value' => '', |
29
|
|
|
]) |
30
|
|
|
->setRequired('route_name') |
31
|
|
|
; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options): void |
35
|
|
|
{ |
36
|
|
|
$text = null; |
37
|
|
|
|
38
|
|
|
if (null !== $data = $form->getData()) { |
39
|
|
|
if (null !== $options['property']) { |
40
|
|
|
$accessor = PropertyAccess::createPropertyAccessor(); |
41
|
|
|
$accessor->getValue($data, $options['property']); |
42
|
|
|
} else { |
43
|
|
|
$text = (string) $data; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$view->vars['text'] = $text; |
48
|
|
|
$view->vars['route_name'] = $options['route_name']; |
49
|
|
|
$view->vars['empty_value'] = $options['empty_value']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getBlockPrefix() |
53
|
|
|
{ |
54
|
|
|
return 'core23_autocomplete'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getParent() |
58
|
|
|
{ |
59
|
|
|
return BaseAutocompleteType::class; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|