|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file was created by developers working at BitBag |
|
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
|
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace BitBag\SyliusCmsPlugin\Form\Type; |
|
12
|
|
|
|
|
13
|
|
|
use BitBag\SyliusCmsPlugin\Form\Type\Translation\MediaTranslationType; |
|
14
|
|
|
use Sylius\Bundle\ChannelBundle\Form\Type\ChannelChoiceType; |
|
15
|
|
|
use Sylius\Bundle\ProductBundle\Form\Type\ProductAutocompleteChoiceType; |
|
16
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; |
|
17
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType; |
|
18
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
20
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType; |
|
21
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
22
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
23
|
|
|
|
|
24
|
|
|
final class MediaType extends AbstractResourceType |
|
25
|
|
|
{ |
|
26
|
|
|
/** @var array */ |
|
27
|
|
|
private $providers; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct( |
|
30
|
|
|
string $dataClass, |
|
31
|
|
|
array $validationGroups = [], |
|
32
|
|
|
array $providers = [] |
|
33
|
|
|
) { |
|
34
|
|
|
parent::__construct($dataClass, $validationGroups); |
|
35
|
|
|
|
|
36
|
|
|
$this->providers = $providers; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
40
|
|
|
{ |
|
41
|
|
|
$data = $builder->getData(); |
|
42
|
|
|
|
|
43
|
|
|
$builder |
|
44
|
|
|
->add('code', TextType::class, [ |
|
45
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.code', |
|
46
|
|
|
'disabled' => null !== $data && null !== $data->getCode(), |
|
47
|
|
|
]) |
|
48
|
|
|
->add('type', ChoiceType::class, [ |
|
49
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.type', |
|
50
|
|
|
'choices' => $this->providers, |
|
51
|
|
|
]) |
|
52
|
|
|
->add('file', FileType::class, [ |
|
53
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.file', |
|
54
|
|
|
]) |
|
55
|
|
|
->add('sections', SectionAutocompleteChoiceType::class, [ |
|
56
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.sections', |
|
57
|
|
|
'multiple' => true, |
|
58
|
|
|
]) |
|
59
|
|
|
->add('enabled', CheckboxType::class, [ |
|
60
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.enabled', |
|
61
|
|
|
]) |
|
62
|
|
|
->add('products', ProductAutocompleteChoiceType::class, [ |
|
63
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.products', |
|
64
|
|
|
'multiple' => true, |
|
65
|
|
|
]) |
|
66
|
|
|
->add('channels', ChannelChoiceType::class, [ |
|
67
|
|
|
'label' => 'bitbag_sylius_cms_plugin.ui.channels', |
|
68
|
|
|
'required' => false, |
|
69
|
|
|
'multiple' => true, |
|
70
|
|
|
'expanded' => true, |
|
71
|
|
|
]) |
|
72
|
|
|
->add('translations', ResourceTranslationsType::class, [ |
|
73
|
|
|
'entry_type' => MediaTranslationType::class, |
|
74
|
|
|
]) |
|
75
|
|
|
; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getBlockPrefix(): string |
|
79
|
|
|
{ |
|
80
|
|
|
return 'bitbag_sylius_cms_plugin_media'; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|