Passed
Push — master ( 6bf791...b01f38 )
by Julito
09:10
created

UserAdmin::configureFormFields()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 106
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 54
nc 2
nop 1
dl 0
loc 106
rs 9.0036
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\UserBundle\Admin;
5
6
use Sonata\AdminBundle\Datagrid\DatagridMapper;
7
use Sonata\AdminBundle\Form\FormMapper;
8
use Sonata\AdminBundle\Form\Type\ModelType;
9
use Sonata\UserBundle\Admin\Model\UserAdmin as BaseUserAdmin;
10
use Sonata\UserBundle\Form\Type\SecurityRolesType;
11
use Symfony\Component\Form\Extension\Core\Type\TextType;
12
13
/**
14
 * Class UserAdmin.
15
 *
16
 * @package Chamilo\UserBundle\Admin
17
 */
18
class UserAdmin extends BaseUserAdmin
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function configureFormFields(FormMapper $formMapper): void
24
    {
25
        // define group zoning
26
        $formMapper
27
            ->tab('User')
28
            ->with('Profile', ['class' => 'col-md-6'])->end()
29
            ->with('General', ['class' => 'col-md-6'])->end()
30
            //->with('Social', array('class' => 'col-md-6'))->end()
31
            ->end()
32
            ->tab('Security')
33
            ->with('Status', ['class' => 'col-md-4'])->end()
34
            ->with('Groups', ['class' => 'col-md-4'])->end()
35
            ->with('Keys', ['class' => 'col-md-4'])->end()
36
            ->with('Roles', ['class' => 'col-md-12'])->end()
37
            ->end()
38
            ->tab('ExtraFields')
39
            ->with('ExtraFields', ['class' => 'col-md-4'])->end()
40
            ->end();
41
42
        $now = new \DateTime();
43
44
        $formMapper
45
            ->tab('User')
46
            ->with('General')
47
                ->add('username')
48
                ->add('email')
49
                /*->add(
50
                    'plainPassword',
51
                    'text',
52
                    array(
53
                        'required' => (!$this->getSubject() || is_null(
54
                                $this->getSubject()->getId()
55
                            )),
56
                    )
57
                )*/
58
            ->end()
59
            ->with('Profile')
60
                /*->add(
61
                    'dateOfBirth',
62
                    'sonata_type_date_picker',
63
                    array(
64
                        'years' => range(1900, $now->format('Y')),
65
                        'dp_min_date' => '1-1-1900',
66
                        'dp_max_date' => $now->format('c'),
67
                        'required' => false,
68
                    )
69
                )*/
70
            ->add('firstname', null, ['required' => false])
71
            ->add('lastname', null, ['required' => false])
72
//            ->add('website', 'url', ['required' => false])
73
            ->add('biography', TextType::class, ['required' => false])
74
            /*->add(
75
                'gender',
76
                'sonata_user_gender',
77
                array(
78
                    'required' => true,
79
                    'translation_domain' => $this->getTranslationDomain(),
80
                )
81
            )*/
82
            //->add('locale', 'locale', array('required' => false))
83
            //->add('timezone', 'timezone', array('required' => false))
84
            //->add('phone', null, array('required' => false))
85
            ->end()
86
            /*->with('Social')
87
            ->add('facebookUid', null, array('required' => false))
88
            ->add('facebookName', null, array('required' => false))
89
            ->add('twitterUid', null, array('required' => false))
90
            ->add('twitterName', null, array('required' => false))
91
            ->add('gplusUid', null, array('required' => false))
92
            ->add('gplusName', null, array('required' => false))
93
            ->end()*/
94
            ->end();
95
96
        if ($this->getSubject() && !$this->getSubject()->hasRole('ROLE_SUPER_ADMIN')) {
97
            $formMapper
98
                ->tab('Security')
99
                ->with('Status')
100
                ->add('locked', null, ['required' => false])
101
                ->add('expired', null, ['required' => false])
102
                ->add('enabled', null, ['required' => false])
103
                ->add('credentialsExpired', null, ['required' => false])
104
                ->end()
105
                ->with('Groups')
106
                ->add(
107
                    'groups',
108
                    ModelType::class,
109
                    [
110
                        'required' => false,
111
                        'expanded' => true,
112
                        'multiple' => true,
113
                    ]
114
                )
115
                ->end()
116
                ->with('Roles')
117
                ->add(
118
                    'realRoles',
119
                    SecurityRolesType::class,
120
                    [
121
                        'label' => 'form.label_roles',
122
                        'expanded' => true,
123
                        'multiple' => true,
124
                        'required' => false,
125
                    ]
126
                )
127
                ->end()
128
                ->end();
129
        }
130
131
        /*$formMapper
132
            ->tab('Security')
133
            ->with('Keys')
134
            ->add('token', null, array('required' => false))
135
            ->add('twoStepVerificationCode', null, array('required' => false))
136
            ->end()
137
            ->end();*/
138
//
139
//        $formMapper
140
//            ->tab('ExtraFields')
141
//            ->with('ExtraFields')
142
//            ->add(
143
//                'extraFields',
144
//                'sonata_type_collection',
145
//                array(
146
//                    'cascade_validation' => true,
147
//                    /*'type_options' => array(
148
//                        // Prevents the "Delete" option from being displayed
149
//                        'delete' => false,
150
//                        'delete_options' => array(
151
//                            // You may otherwise choose to put the field but hide it
152
//                            'type'         => 'hidden',
153
//                            // In that case, you need to fill in the options as well
154
//                            'type_options' => array(
155
//                                'mapped'   => false,
156
//                                'required' => false,
157
//                            )
158
//                        )
159
//                    )*/
160
//                ),
161
//                array(
162
//                    'allow_delete' => true,
163
//                    'by_reference' => false,
164
//                    'edit' => 'inline',
165
//                    'inline' => 'table',
166
//                    'admin_code' => 'sonata.admin.user_field_values'
167
//                    /* 'edit' => 'inline',
168
//                     'inline' => 'table',
169
//                     'sortable' => 'position',*/
170
//                )
171
//            )
172
//            ->end()
173
//            ->end();
174
    }
175
176
    /**
177
     * @param DatagridMapper $datagridMapper
178
     */
179
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
180
    {
181
        $datagridMapper
182
            ->add('username')
183
            ->add('firstname')
184
            ->add('lastname')
185
            ->add('email')
186
            ->add('officialCode')
187
            ->add('groups')
188
            ->add('active')
189
            //->add('registrationDate', 'doctrine_orm_datetime_range', array('input_type' => 'timestamp'))
190
        ;
191
    }
192
}
193