1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Setono\SyliusSchedulerPlugin\Form\Type; |
6
|
|
|
|
7
|
|
|
use Setono\SyliusSchedulerPlugin\Doctrine\ORM\ScheduleRepositoryInterface; |
8
|
|
|
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer; |
9
|
|
|
use Symfony\Component\Form\AbstractType; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
11
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
12
|
|
|
use Symfony\Component\OptionsResolver\Options; |
13
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
14
|
|
|
|
15
|
|
|
final class ScheduleChoiceType extends AbstractType |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var ScheduleRepositoryInterface |
19
|
|
|
*/ |
20
|
|
|
private $scheduleRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param ScheduleRepositoryInterface $scheduleRepository |
24
|
|
|
*/ |
25
|
|
|
public function __construct(ScheduleRepositoryInterface $scheduleRepository) |
26
|
|
|
{ |
27
|
|
|
$this->scheduleRepository = $scheduleRepository; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
34
|
|
|
{ |
35
|
|
|
if ($options['multiple']) { |
36
|
|
|
$builder->addModelTransformer(new CollectionToArrayTransformer()); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
44
|
|
|
{ |
45
|
|
|
$resolver->setDefaults([ |
46
|
|
|
'choices' => function (Options $options): array { |
|
|
|
|
47
|
|
|
return $this->scheduleRepository->findAll(); |
48
|
|
|
}, |
49
|
|
|
'choice_value' => 'code', |
50
|
|
|
'choice_label' => 'name', |
51
|
|
|
'choice_translation_domain' => false, |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function getParent(): string |
59
|
|
|
{ |
60
|
|
|
return ChoiceType::class; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function getBlockPrefix(): string |
67
|
|
|
{ |
68
|
|
|
return 'setono_sylius_scheduler_schedule_choice'; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.