-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathCroppableGalleryType.php
More file actions
147 lines (120 loc) · 4.89 KB
/
Copy pathCroppableGalleryType.php
File metadata and controls
147 lines (120 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
namespace Comur\ImageBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
// use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CroppableGalleryType extends CroppableImageType
{
protected $galleryDir = null;
protected $thumbsDir = null;
protected $isGallery = true;
protected $galleryThumbSize = null;
// public function getParent()
// {
// return 'collection';
// }
public function getBlockPrefix()
{
return 'comur_gallery';
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// if($options['uploadConfig']['saveOriginal']){
// $form->getParent()->add($options['uploadConfig']['saveOriginal'], 'hidden');
// }
// var_dump($builder->getDataMapper());exit;
// if($options['uploadConfig']['saveOriginal']){
// $builder->add($options['uploadConfig']['saveOriginal'], 'text', array(
// // 'inherit_data' => true,
// // 'property_path' => $options['uploadConfig']['saveOriginal'],
// 'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
// }
$builder->add($builder->getName(), CollectionType::class, array(
// 'property_path' => $builder->getName(),
// 'inherit_data' => true,
'allow_add' => function(Options $options, $value){ return true; },
'allow_delete' => function(Options $options, $value){ return true; },
'entry_options' => array(
'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;padding: 0; position: absolute;'
)
)
));
}
public function __construct($galleryDir, $thumbsDir, $galleryThumbSize)
{
$this->galleryDir = $galleryDir;
$this->thumbsDir = $thumbsDir;
$this->galleryThumbSize = $galleryThumbSize;
}
/**
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$galleryDir = $this->galleryDir;
// $resolver->setNormalizers(array(
// ));
// $uploadConfig = array(
// 'uploadRoute' => 'comur_api_upload',
// 'uploadUrl' => null,
// 'webDir' => null,
// 'fileExt' => '*.jpg;*.gif;*.png;*.jpeg',
// 'libraryDir' => null,
// 'libraryRoute' => 'comur_api_image_library',
// 'showLibrary' => true
// );
// $cropConfig = array(
// 'minWidth' => 1,
// 'minHeight' => 1,
// 'aspectRatio' => true,
// 'cropRoute' => 'comur_api_crop',
// 'forceResize' => false,
// 'thumbs' => null
// );
// $resolver->setDefaults(array(
// 'uploadConfig' => $uploadConfig,
// 'cropConfig' => $cropConfig,
// ));
// $resolver->setNormalizers(array(
// 'uploadConfig' => function(Options $options, $value) use ($uploadConfig){
// $config = array_merge($uploadConfig, $value);
// if(!isset($config['libraryDir'])){
// $config['libraryDir'] = $config['uploadUrl'];
// }
// return $config;
// },
// 'cropConfig' => function(Options $options, $value) use($cropConfig){
// return array_merge($cropConfig, $value);
// }
// ));
}
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
// @Tersoal
// Hack to fix windows routes. Windows create routes with \ instead of /
foreach($options['uploadConfig'] as $key => $optiontotransform) {
$options['uploadConfig'][$key] = str_replace('\\', '/', $optiontotransform);
}
// @Tersoal
$uploadConfig = $options['uploadConfig'];
$cropConfig = $options['cropConfig'];
// $options['type'] = 'text';
// var_dump($options);exit;
$uploadConfig['isGallery'] = true;
$view->vars['options'] = array('uploadConfig' => $uploadConfig, 'cropConfig' => $cropConfig, 'galleryThumbSize' => $this->galleryThumbSize);
// $view->vars['options']['attr'] = array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;', 'multiple' => true);
// $view->vars['attr'] = array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;', 'multiple' => true);
}
}