UserSearchType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 2
cbo 6
dl 0
loc 78
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultOptions() 0 16 1
A __construct() 0 6 1
A buildForm() 0 6 1
A buildView() 0 4 1
A getParent() 0 4 1
A getName() 0 4 1
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