Skip to content

Commit a77434d

Browse files
committed
* Readme images
* Added a callback parameter for javascript init call (ComurContentAdminBundle compatibility) * Fixed gallery SF4 bug * Readme updated
1 parent 55e8fa9 commit a77434d

13 files changed

Lines changed: 190 additions & 188 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/Tests/*
22
!Tests/.gitkeep
33
.DS_Store
4-
.idea
4+
._.DS_Store
5+
.unison*
6+
.idea

Form/Type/CroppableGalleryType.php

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ class CroppableGalleryType extends CroppableImageType
2020
protected $isGallery = true;
2121
protected $galleryThumbSize = null;
2222

23-
// public function getParent()
24-
// {
25-
// return 'collection';
26-
// }
27-
2823
public function getBlockPrefix()
2924
{
3025
return 'comur_gallery';
@@ -36,27 +31,15 @@ public function getBlockPrefix()
3631
public function buildForm(FormBuilderInterface $builder, array $options)
3732
{
3833

39-
// if($options['uploadConfig']['saveOriginal']){
40-
// $form->getParent()->add($options['uploadConfig']['saveOriginal'], 'hidden');
41-
// }
42-
// var_dump($builder->getDataMapper());exit;
43-
// if($options['uploadConfig']['saveOriginal']){
44-
// $builder->add($options['uploadConfig']['saveOriginal'], 'text', array(
45-
// // 'inherit_data' => true,
46-
// // 'property_path' => $options['uploadConfig']['saveOriginal'],
47-
// 'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
48-
// }
49-
5034
$builder->add($builder->getName(), CollectionType::class, array(
5135
// 'property_path' => $builder->getName(),
5236
// 'inherit_data' => true,
53-
'allow_add' => function(Options $options, $value){ return true; },
54-
'allow_delete' => function(Options $options, $value){ return true; },
37+
'allow_add' => true,
38+
'allow_delete' => true,
5539
'entry_options' => array(
56-
'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;padding: 0; position: absolute;'
57-
)
58-
)
59-
));
40+
'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;padding: 0; position: absolute;')
41+
)
42+
));
6043
}
6144

6245
public function __construct($galleryDir, $thumbsDir, $galleryThumbSize)
@@ -66,70 +49,13 @@ public function __construct($galleryDir, $thumbsDir, $galleryThumbSize)
6649
$this->galleryThumbSize = $galleryThumbSize;
6750
}
6851

69-
/**
70-
* {@inheritDoc}
71-
*/
72-
public function configureOptions(OptionsResolver $resolver)
73-
{
74-
75-
76-
parent::configureOptions($resolver);
77-
78-
$galleryDir = $this->galleryDir;
79-
80-
// $resolver->setNormalizers(array(
81-
82-
83-
// ));
84-
// $uploadConfig = array(
85-
// 'uploadRoute' => 'comur_api_upload',
86-
// 'uploadUrl' => null,
87-
// 'webDir' => null,
88-
// 'fileExt' => '*.jpg;*.gif;*.png;*.jpeg',
89-
// 'libraryDir' => null,
90-
// 'libraryRoute' => 'comur_api_image_library',
91-
// 'showLibrary' => true
92-
// );
93-
94-
// $cropConfig = array(
95-
// 'minWidth' => 1,
96-
// 'minHeight' => 1,
97-
// 'aspectRatio' => true,
98-
// 'cropRoute' => 'comur_api_crop',
99-
// 'forceResize' => false,
100-
// 'thumbs' => null
101-
// );
102-
103-
// $resolver->setDefaults(array(
104-
// 'uploadConfig' => $uploadConfig,
105-
// 'cropConfig' => $cropConfig,
106-
// ));
107-
108-
// $resolver->setNormalizers(array(
109-
// 'uploadConfig' => function(Options $options, $value) use ($uploadConfig){
110-
// $config = array_merge($uploadConfig, $value);
111-
// if(!isset($config['libraryDir'])){
112-
// $config['libraryDir'] = $config['uploadUrl'];
113-
// }
114-
// return $config;
115-
// },
116-
// 'cropConfig' => function(Options $options, $value) use($cropConfig){
117-
// return array_merge($cropConfig, $value);
118-
// }
119-
// ));
120-
121-
}
122-
12352
/**
12453
* {@inheritdoc}
12554
*/
12655
public function buildView(FormView $view, FormInterface $form, array $options)
12756
{
12857
$uploadConfig = $options['uploadConfig'];
12958
$cropConfig = $options['cropConfig'];
130-
// $options['type'] = 'text';
131-
132-
// var_dump($options);exit;
13359

13460
$uploadConfig['isGallery'] = true;
13561

Form/Type/CroppableImageType.php

Lines changed: 67 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ class CroppableImageType extends AbstractType
2020
protected $galleryDir = null;
2121
protected $thumbsDir = null;
2222

23+
static $uploadConfig = array(
24+
'uploadRoute' => 'comur_api_upload',
25+
'uploadUrl' => null,
26+
'webDir' => null,
27+
'fileExt' => '*.jpg;*.gif;*.png;*.jpeg',
28+
'libraryDir' => null,
29+
'libraryRoute' => 'comur_api_image_library',
30+
'showLibrary' => true,
31+
'saveOriginal' => false, //save original file name
32+
'generateFilename' => true //generate an uniq filename
33+
);
34+
35+
static $cropConfig = array(
36+
// 'disableCrop' => false,
37+
'minWidth' => 1,
38+
'minHeight' => 1,
39+
'aspectRatio' => true,
40+
'cropRoute' => 'comur_api_crop',
41+
'forceResize' => false,
42+
'thumbs' => null
43+
);
44+
2345
// public function getParent()
2446
// {
2547
// return 'text';
@@ -40,7 +62,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4062
// $form->getParent()->add($options['uploadConfig']['saveOriginal'], 'hidden');
4163
// }
4264
// var_dump($builder->getDataMapper());exit;
43-
if($options['uploadConfig']['saveOriginal']){
65+
if ($options['uploadConfig']['saveOriginal']) {
4466
$builder->add($options['uploadConfig']['saveOriginal'], TextType::class, array(
4567
// 'inherit_data' => true,
4668
// 'property_path' => $options['uploadConfig']['saveOriginal'],
@@ -52,33 +74,51 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5274
'attr' => array('style' => 'opacity: 0;width: 0; max-width: 0; height: 0; max-height: 0;')));
5375
}
5476

77+
/**
78+
* Returns upload config normalizer. It can be used by compatible bundles to normalize parameters
79+
* @param $uploadConfig
80+
* @param $isGallery
81+
* @param $galleryDir
82+
* @return \Closure
83+
*/
84+
public static function getUploadConfigNormalizer($uploadConfig, $isGallery = false, $galleryDir = null) {
85+
return function (Options $options, $value) use ($uploadConfig, $isGallery, $galleryDir) {
86+
$config = array_merge($uploadConfig, $value);
87+
88+
if ($isGallery) {
89+
$config['uploadUrl'] = $config['uploadUrl'] . '/' . $galleryDir;
90+
$config['webDir'] = $config['webDir'] . '/' . $galleryDir;
91+
$config['saveOriginal'] = false;
92+
}
93+
94+
if (!isset($config['libraryDir'])) {
95+
$config['libraryDir'] = $config['uploadUrl'];
96+
}
97+
// if($config['saveOriginal']){
98+
// $options['compound']=true;
99+
// }
100+
return $config;
101+
};
102+
}
103+
104+
/**
105+
* Returns crop config normalizer. It can be used by compatible bundles to normalize parameters
106+
* @param $cropConfig
107+
* @return \Closure
108+
*/
109+
public static function getCropConfigNormalizer($cropConfig) {
110+
return function (Options $options, $value) use ($cropConfig) {
111+
return array_merge($cropConfig, $value);
112+
};
113+
}
114+
55115
/**
56116
* {@inheritDoc}
57117
*/
58118
public function configureOptions(OptionsResolver $resolver)
59119
{
60-
61-
$uploadConfig = array(
62-
'uploadRoute' => 'comur_api_upload',
63-
'uploadUrl' => null,
64-
'webDir' => null,
65-
'fileExt' => '*.jpg;*.gif;*.png;*.jpeg',
66-
'libraryDir' => null,
67-
'libraryRoute' => 'comur_api_image_library',
68-
'showLibrary' => true,
69-
'saveOriginal' => false, //save original file name
70-
'generateFilename' => true //generate an uniq filename
71-
);
72-
73-
$cropConfig = array(
74-
// 'disableCrop' => false,
75-
'minWidth' => 1,
76-
'minHeight' => 1,
77-
'aspectRatio' => true,
78-
'cropRoute' => 'comur_api_crop',
79-
'forceResize' => true,
80-
'thumbs' => null
81-
);
120+
$uploadConfig = self::$uploadConfig;
121+
$cropConfig = self::$cropConfig;
82122

83123
$resolver->setDefaults(array(
84124
'uploadConfig' => $uploadConfig,
@@ -95,28 +135,10 @@ public function configureOptions(OptionsResolver $resolver)
95135
$galleryDir = $this->galleryDir;
96136

97137
$resolver->setNormalizer(
98-
'uploadConfig', function(Options $options, $value) use ($uploadConfig, $isGallery, $galleryDir){
99-
$config = array_merge($uploadConfig, $value);
100-
101-
if($isGallery){
102-
$config['uploadUrl'] = $config['uploadUrl'].'/'.$galleryDir;
103-
$config['webDir'] = $config['webDir'].'/'.$galleryDir;
104-
$config['saveOriginal'] = false;
105-
}
106-
107-
if(!isset($config['libraryDir'])){
108-
$config['libraryDir'] = $config['uploadUrl'];
109-
}
110-
// if($config['saveOriginal']){
111-
// $options['compound']=true;
112-
// }
113-
return $config;
114-
}
138+
'uploadConfig', self::getUploadConfigNormalizer($uploadConfig, $isGallery, $galleryDir)
115139
);
116140
$resolver->setNormalizer(
117-
'cropConfig', function(Options $options, $value) use($cropConfig){
118-
return array_merge($cropConfig, $value);
119-
}
141+
'cropConfig', self::getCropConfigNormalizer($cropConfig)
120142
);
121143

122144
}
@@ -140,11 +162,9 @@ public function buildView(FormView $view, FormInterface $form, array $options)
140162
$cropConfig = $options['cropConfig'];
141163

142164
$fieldImage = null;
143-
if(isset($cropConfig['thumbs']) && count($thumbs = $cropConfig['thumbs']) > 0)
144-
{
165+
if (isset($cropConfig['thumbs']) && count($thumbs = $cropConfig['thumbs']) > 0) {
145166
foreach ($thumbs as $thumb) {
146-
if(isset($thumb['useAsFieldImage']) && $thumb['useAsFieldImage'])
147-
{
167+
if (isset($thumb['useAsFieldImage']) && $thumb['useAsFieldImage']) {
148168
$fieldImage = $thumb;
149169
}
150170
}

0 commit comments

Comments
 (0)