These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Form; |
||
4 | |||
5 | use Doctrine\ORM\EntityRepository; |
||
6 | use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
||
7 | use Symfony\Component\Form\AbstractType; |
||
8 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
||
9 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
||
10 | use Symfony\Component\Form\Extension\Core\Type\EmailType; |
||
11 | use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
||
12 | use Symfony\Component\Form\Extension\Core\Type\RepeatedType; |
||
13 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
||
14 | use Symfony\Component\Form\FormBuilderInterface; |
||
15 | use Symfony\Component\OptionsResolver\OptionsResolver; |
||
16 | |||
17 | /** |
||
18 | * UserType defines the form used for {@link User} |
||
19 | */ |
||
20 | class UserType extends AbstractType implements RoleDependentUserFormInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | private $canEditAllFields = false; |
||
26 | |||
27 | /** |
||
28 | * Setter to check if we can display all form fields |
||
29 | * |
||
30 | * @param $canEditAllFields |
||
31 | * @return bool |
||
0 ignored issues
–
show
|
|||
32 | */ |
||
33 | public function setCanEditAllFields($canEditAllFields) |
||
34 | { |
||
35 | $this->canEditAllFields = (bool)$canEditAllFields; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
42 | { |
||
43 | $languages = array(); |
||
44 | foreach ($options['langs'] as $lang) { |
||
45 | $languages[$lang] = $lang; |
||
46 | } |
||
47 | |||
48 | $this->canEditAllFields = $options['can_edit_all_fields']; |
||
49 | |||
50 | $builder->add('username', TextType::class, array ('required' => true, 'label' => 'settings.user.username')) |
||
51 | ->add('plainPassword', RepeatedType::class, array( |
||
52 | 'type' => PasswordType::class, |
||
53 | 'required' => $options['password_required'], |
||
54 | 'invalid_message' => 'errors.password.dontmatch', |
||
55 | 'first_options' => array( |
||
56 | 'label' => 'settings.user.password' |
||
57 | ), |
||
58 | 'second_options' => array( |
||
59 | 'label' => 'settings.user.repeatedpassword' |
||
60 | ) |
||
61 | )) |
||
62 | ->add('email', EmailType::class, array ('required' => true, 'label' => 'settings.user.email')) |
||
63 | ->add('adminLocale', ChoiceType::class, array( |
||
64 | 'choices' => $languages, |
||
65 | 'label' => 'settings.user.adminlang', |
||
66 | 'required' => true, |
||
67 | 'placeholder' => false, |
||
68 | )); |
||
69 | |||
70 | if ($this->canEditAllFields) { |
||
71 | $builder->add('enabled', CheckboxType::class, array('required' => false, 'label' => 'settings.user.enabled')) |
||
72 | ->add('groups', EntityType::class, array( |
||
73 | 'label' => 'settings.user.roles', |
||
74 | 'class' => 'KunstmaanAdminBundle:Group', |
||
75 | 'query_builder' => function(EntityRepository $er) { |
||
76 | return $er->createQueryBuilder('g') |
||
77 | ->orderBy('g.name', 'ASC'); |
||
78 | }, |
||
79 | 'multiple' => true, |
||
80 | 'expanded' => false, |
||
81 | 'required' => false, |
||
82 | 'attr' => array( |
||
83 | 'placeholder' => 'settings.user.roles_placeholder', |
||
84 | 'class' => 'js-advanced-select form-control advanced-select', |
||
85 | ) |
||
86 | ) |
||
87 | ); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function getBlockPrefix() |
||
95 | { |
||
96 | return 'user'; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function configureOptions(OptionsResolver $resolver) |
||
103 | { |
||
104 | $resolver->setDefaults( |
||
105 | array( |
||
106 | 'password_required' => false, |
||
107 | 'data_class' => 'Kunstmaan\AdminBundle\Entity\User', |
||
108 | 'langs' => null, |
||
109 | 'can_edit_all_fields' => null, |
||
110 | ) |
||
111 | ); |
||
112 | $resolver->addAllowedValues('password_required', array(true, false)); |
||
113 | } |
||
114 | } |
||
115 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.