1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2017 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2017 Sourcefabric z.ú |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace SWP\Bundle\MultiTenancyBundle\Form\Type; |
18
|
|
|
|
19
|
|
|
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface; |
20
|
|
|
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer; |
21
|
|
|
use Symfony\Component\Form\AbstractType; |
22
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
23
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
24
|
|
|
use Symfony\Component\OptionsResolver\Options; |
25
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
26
|
|
|
|
27
|
|
|
final class TenantChoiceType extends AbstractType |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var TenantRepositoryInterface |
31
|
|
|
*/ |
32
|
|
|
private $tenantRepository; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* TenantChoiceType constructor. |
36
|
|
|
* |
37
|
|
|
* @param TenantRepositoryInterface $tenantRepository |
38
|
|
|
*/ |
39
|
|
|
public function __construct(TenantRepositoryInterface $tenantRepository) |
40
|
|
|
{ |
41
|
|
|
$this->tenantRepository = $tenantRepository; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
48
|
|
|
{ |
49
|
|
|
if ($options['multiple']) { |
50
|
|
|
$builder->addModelTransformer(new CollectionToArrayTransformer()); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function configureOptions(OptionsResolver $resolver) |
58
|
|
|
{ |
59
|
|
|
$resolver->setDefaults([ |
60
|
|
|
'choices' => function (Options $options) { |
|
|
|
|
61
|
|
|
return $this->tenantRepository->findAll(); |
62
|
|
|
}, |
63
|
|
|
'choice_value' => 'code', |
64
|
|
|
'choice_label' => 'name', |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function getParent() |
72
|
|
|
{ |
73
|
|
|
return ChoiceType::class; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function getBlockPrefix() |
80
|
|
|
{ |
81
|
|
|
return ''; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.