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\Entity\MediaInterface; |
14
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType; |
15
|
|
|
use Symfony\Component\Form\AbstractType; |
16
|
|
|
use Symfony\Component\Form\FormInterface; |
17
|
|
|
use Symfony\Component\Form\FormView; |
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
19
|
|
|
|
20
|
|
|
final class MediaAutocompleteChoiceType extends AbstractType |
21
|
|
|
{ |
22
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
23
|
|
|
{ |
24
|
|
|
$resolver->setDefaults([ |
25
|
|
|
'resource' => 'bitbag_sylius_cms_plugin.media', |
26
|
|
|
'choice_name' => 'name', |
27
|
|
|
'choice_value' => 'code', |
28
|
|
|
'media_type' => null, |
29
|
|
|
]); |
30
|
|
|
|
31
|
|
|
$resolver->setAllowedValues('media_type', [ |
32
|
|
|
MediaInterface::IMAGE_TYPE, |
33
|
|
|
MediaInterface::FILE_TYPE, |
34
|
|
|
MediaInterface::VIDEO_TYPE, |
35
|
|
|
null, |
36
|
|
|
]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function buildView( |
40
|
|
|
FormView $view, |
41
|
|
|
FormInterface $form, |
42
|
|
|
array $options |
43
|
|
|
): void { |
44
|
|
|
$view->vars['remote_criteria_type'] = 'contains'; |
45
|
|
|
$view->vars['remote_criteria_name'] = 'phrase'; |
46
|
|
|
$view->vars['media_type'] = $options['media_type']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getBlockPrefix(): string |
50
|
|
|
{ |
51
|
|
|
return 'bitbag_media_autocomplete_choice'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getParent(): string |
55
|
|
|
{ |
56
|
|
|
return ResourceAutocompleteChoiceType::class; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|