|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the IrishDan\ResponsiveImageBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Daniel Byrne <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE file that was distributed with this source |
|
8
|
|
|
* code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace IrishDan\ResponsiveImageBundle\Form; |
|
12
|
|
|
|
|
13
|
|
|
use IrishDan\ResponsiveImageBundle\StyleManager; |
|
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
|
15
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
16
|
|
|
use Symfony\Component\Form\FormInterface; |
|
17
|
|
|
use Symfony\Component\Form\FormView; |
|
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
19
|
|
|
use Symfony\Component\Form\AbstractType; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class CropFocusType |
|
23
|
|
|
* |
|
24
|
|
|
* @package ResponsiveImageBundle\Form\Type |
|
25
|
|
|
*/ |
|
26
|
|
|
class CropFocusType extends AbstractType |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var StyleManager |
|
30
|
|
|
*/ |
|
31
|
|
|
private $styleManager; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var bool |
|
34
|
|
|
*/ |
|
35
|
|
|
private $displayCoordinates = true; |
|
36
|
|
|
/** |
|
37
|
|
|
* @var bool |
|
38
|
|
|
*/ |
|
39
|
|
|
private $includeJsCss = true; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* CropFocusType constructor. |
|
43
|
|
|
* |
|
44
|
|
|
* @param StyleManager $styleManager |
|
45
|
|
|
* @param array $configuration |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(StyleManager $styleManager, array $configuration) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->styleManager = $styleManager; |
|
50
|
|
|
|
|
51
|
|
|
if (!empty($configuration['crop_focus_widget'])) { |
|
52
|
|
|
$this->includeJsCss = empty($configuration['crop_focus_widget']['include_js_css']) ? false : true; |
|
53
|
|
|
$this->displayCoordinates = empty($configuration['crop_focus_widget']['display_coordinates']) ? false : true; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param OptionsResolver $resolver |
|
59
|
|
|
*/ |
|
60
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
61
|
|
|
{ |
|
62
|
|
|
$resolver->setDefaults( |
|
63
|
|
|
[ |
|
64
|
|
|
'label' => 'Focus and Crop', |
|
65
|
|
|
'empty_data' => '0, 0, 0, 0:0, 0, 0, 0', |
|
66
|
|
|
'alt' => 'Alt', |
|
67
|
|
|
'title' => 'title', |
|
68
|
|
|
'width' => 100, |
|
69
|
|
|
'height' => 100, |
|
70
|
|
|
'display_coordinates' => $this->displayCoordinates, |
|
71
|
|
|
'include_js_css' => $this->includeJsCss, |
|
72
|
|
|
'coordinate_field_type' => $this->displayCoordinates ? 'text' : 'hidden', |
|
73
|
|
|
] |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param FormBuilderInterface $builder |
|
79
|
|
|
* @param array $options |
|
80
|
|
|
*/ |
|
81
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
82
|
|
|
{ |
|
83
|
|
|
parent::buildForm($builder, $options); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param FormView $view |
|
88
|
|
|
* @param FormInterface $form |
|
89
|
|
|
* @param array $options |
|
90
|
|
|
*/ |
|
91
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options) |
|
92
|
|
|
{ |
|
93
|
|
|
parent::buildView($view, $form, $options); |
|
94
|
|
|
|
|
95
|
|
|
$image = $options['data']; |
|
96
|
|
|
$options['value'] = $image->getCropCoordinates(); |
|
97
|
|
|
$options['image'] = $image; |
|
98
|
|
|
|
|
99
|
|
|
if ($options['include_js_css']) { |
|
100
|
|
|
$pubicDirectory = dirname(__FILE__) . '/../Resources/public/'; |
|
101
|
|
|
$js = file_get_contents($pubicDirectory . 'js/jquery.cropper.js', FILE_USE_INCLUDE_PATH); |
|
102
|
|
|
$css = file_get_contents($pubicDirectory . 'css/cropper.css', FILE_USE_INCLUDE_PATH); |
|
103
|
|
|
|
|
104
|
|
|
$options['js'] = $js; |
|
105
|
|
|
$options['css'] = $css; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$view->vars = array_replace($view->vars, $options); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return mixed |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getParent() |
|
115
|
|
|
{ |
|
116
|
|
|
return HiddenType::class; |
|
117
|
|
|
} |
|
118
|
|
|
} |