1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoS\UserBundle\Form\Type; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Form\AbstractType; |
6
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
7
|
|
|
use Symfony\Component\Form\FormInterface; |
8
|
|
|
use Symfony\Component\Form\FormView; |
9
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
10
|
|
|
use Symfony\Component\Routing\RouterInterface; |
11
|
|
|
use DoS\ResourceBundle\Form\DataTransformer\IdentifierToObjectTransformer; |
12
|
|
|
use DoS\UserBundle\Doctrine\ORM\UserRepository; |
13
|
|
|
|
14
|
|
|
class UserSearchType extends AbstractType |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var UserRepository |
18
|
|
|
*/ |
19
|
|
|
private $repository; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var RouterInterface |
23
|
|
|
*/ |
24
|
|
|
private $router; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $route; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function __construct(UserRepository $repository, RouterInterface $router, $route) |
35
|
|
|
{ |
36
|
|
|
$this->repository = $repository; |
37
|
|
|
$this->router = $router; |
38
|
|
|
$this->route = $route; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
45
|
|
|
{ |
46
|
|
|
$builder->addModelTransformer( |
47
|
|
|
new IdentifierToObjectTransformer($this->repository, $options['identifier']) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options) |
55
|
|
|
{ |
56
|
|
|
$view->vars['selectize'] = $options['selectize']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function setDefaultOptions(OptionsResolverInterface $resolver) |
63
|
|
|
{ |
64
|
|
|
$resolver->setDefaults(array( |
65
|
|
|
'required' => true, |
66
|
|
|
'identifier' => 'username', |
67
|
|
|
'attr' => array('placeholder' => 'ui.trans.user.search'), |
68
|
|
|
'selectize' => array( |
69
|
|
|
'plugins' => array(), |
70
|
|
|
'valueField' => 'username', |
71
|
|
|
'labelField' => 'displayname', |
72
|
|
|
'searchField' => ['username', 'displayname'], |
73
|
|
|
'tpl' => 'tpl-user-selectize', |
74
|
|
|
'url' => $this->router->generate($this->route, array('query' => ':query')), |
75
|
|
|
), |
76
|
|
|
)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getParent() |
80
|
|
|
{ |
81
|
|
|
return 'text'; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
|
|
public function getName() |
88
|
|
|
{ |
89
|
|
|
return 'dos_user_search'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|