RoleAtInstitutionType::getBlockPrefix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2019 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupRa\RaBundle\Form\Type;
20
21
use Surfnet\StepupRa\RaBundle\Form\Extension\RaRoleChoiceList;
22
use Surfnet\StepupRa\RaBundle\Value\RoleAtInstitution;
23
use Symfony\Component\Form\AbstractType;
24
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
25
use Symfony\Component\Form\FormBuilderInterface;
26
use Symfony\Component\OptionsResolver\OptionsResolver;
27
28
/**
29
 * RoleAtInstitutionType
30
 *
31
 * The RoleAtInstitutionType can be used to render a compound form component that consists of a role and an institution
32
 * form field. These are used in conjunction to describe a role of an identity at an insitution.
33
 *
34
 * Use the 'required' option to set the select fields to be either optional (for search) or mandatory.
35
 * Use the 'choices' option to populate the intitutions field, the roles select list is filled with a RaRoleChoiceList
36
 *
37
 * This type can be use for example:
38
 *  - search forms when you want to find identities with a specific role at a given institution
39
 *  - when roles are applied to identities
40
 *
41
 */
42
class RoleAtInstitutionType extends AbstractType
43
{
44
    public function buildForm(FormBuilderInterface $builder, array $options)
45
    {
46
        $selectRaaOptions = $options['choices'];
47
        $isRequired = $options['required'];
48
49
        $builder ->add('role', ChoiceType::class, [
50
            'label' => false,
51
            'choices' => RaRoleChoiceList::create(),
52
            'choice_value' => function ($choice) {
53
                return $choice;
54
            },
55
            'required' => $isRequired,
56
        ])->add('institution', ChoiceType::class, [
57
            'label' => 'ra.form.role_at_institution.label.institution',
58
            'choices' => $selectRaaOptions,
59
            'required' => $isRequired,
60
        ]);
61
    }
62
63
    public function configureOptions(OptionsResolver $resolver)
64
    {
65
        $resolver->setDefaults(array(
66
            'data_class' => RoleAtInstitution::class,
67
            'choices' => [],
68
            'horizontal' => true,
69
            'error_bubbling' => false,
70
        ));
71
    }
72
73
    public function getBlockPrefix()
74
    {
75
        return 'ra_role_at_institution';
76
    }
77
}
78