1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\MediaBundle\Form; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\MediaBundle\Entity\EditableMediaWrapper; |
6
|
|
|
use Kunstmaan\MediaBundle\Form\Type\MediaType; |
7
|
|
|
use Symfony\Component\Form\AbstractType; |
8
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
9
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
10
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
11
|
|
|
|
12
|
|
|
class EditableMediaWrapperAdminType extends AbstractType |
13
|
|
|
{ |
14
|
|
|
private const DEFAULT = 'default'; |
15
|
|
|
private const CUSTOM_VIEWS = 'custom_views'; |
16
|
|
|
private const FOCUS_POINT_CLASSES = 'focus_point_classes'; |
17
|
|
|
|
18
|
|
|
/** @var array */ |
19
|
|
|
private $croppingViews; |
20
|
|
|
|
21
|
|
|
public function __construct(array $croppingViews) |
22
|
|
|
{ |
23
|
|
|
$this->croppingViews = $croppingViews; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
27
|
|
|
{ |
28
|
|
|
$croppingViewGroup = $options['cropping_views_group']; |
29
|
|
|
$selectedCroppingViews = $this->croppingViews[self::DEFAULT]; |
30
|
|
|
$useFocusPoint = false; |
31
|
|
|
$useCropper = true; |
32
|
|
|
$focusPointClasses = $this->croppingViews[self::FOCUS_POINT_CLASSES]; |
33
|
|
|
if ($croppingViewGroup !== self::DEFAULT && isset($this->croppingViews[self::CUSTOM_VIEWS][$croppingViewGroup]['views'])) { |
34
|
|
|
$selectedCroppingViews = $this->croppingViews[self::CUSTOM_VIEWS][$croppingViewGroup]['views']; |
35
|
|
|
$useFocusPoint = $this->croppingViews[self::CUSTOM_VIEWS][$croppingViewGroup]['use_focus_point'] ?? false; |
36
|
|
|
$useCropper = $this->croppingViews[self::CUSTOM_VIEWS][$croppingViewGroup]['use_cropping'] ?? true; |
37
|
|
|
} |
38
|
|
|
$builder->add('media', MediaType::class, [ |
39
|
|
|
'label' => 'mediapagepart.image.choosefile', |
40
|
|
|
'mediatype' => 'image', |
41
|
|
|
'show_image_edit_modal' => true, |
42
|
|
|
'use_focus_point' => $useFocusPoint, |
43
|
|
|
'use_cropping' => $useCropper, |
44
|
|
|
'focus_point_classes' => json_encode($focusPointClasses), |
45
|
|
|
'cropping_views' => json_encode($selectedCroppingViews), |
46
|
|
|
]); |
47
|
|
|
$builder->add('runTimeConfig', HiddenType::class, [ |
48
|
|
|
'label' => false, |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function configureOptions(OptionsResolver $resolver) |
53
|
|
|
{ |
54
|
|
|
$resolver->setDefaults( |
55
|
|
|
[ |
56
|
|
|
'data_class' => EditableMediaWrapper::class, |
57
|
|
|
'cropping_views_group' => self::DEFAULT, |
58
|
|
|
] |
59
|
|
|
); |
60
|
|
|
$groups = array_keys($this->croppingViews[self::CUSTOM_VIEWS]); |
61
|
|
|
$groups[] = self::DEFAULT; |
62
|
|
|
$resolver->setAllowedValues('cropping_views_group', $groups); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|