22
33namespace Victoire \Widget \ImageBundle \Form ;
44
5+ use Ivory \CKEditorBundle \Form \Type \CKEditorType ;
6+ use Symfony \Component \Form \Extension \Core \Type \ChoiceType ;
57use Symfony \Component \Form \FormBuilderInterface ;
68use Symfony \Component \Form \FormEvent ;
79use Symfony \Component \Form \FormEvents ;
810use Symfony \Component \Form \FormInterface ;
9- use Symfony \Component \OptionsResolver \OptionsResolverInterface ;
11+ use Symfony \Component \OptionsResolver \OptionsResolver ;
1012use Victoire \Bundle \CoreBundle \Form \WidgetType ;
13+ use Victoire \Bundle \FormBundle \Form \Type \LinkType ;
14+ use Victoire \Bundle \MediaBundle \Form \Type \MediaType ;
1115use Victoire \Bundle \WidgetBundle \Model \Widget ;
1216
1317/**
@@ -25,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2529 {
2630 if ($ options ['mode ' ] === null || $ options ['mode ' ] === Widget::MODE_STATIC ) {
2731 $ builder
28- ->add ('image ' , ' media ' , [
32+ ->add ('image ' , MediaType::class , [
2933 'label ' => 'widget_image.form.image.label ' ,
3034 ])
3135 ->add ('lazyLoad ' , null , [
@@ -40,19 +44,19 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4044 ->add ('legend ' , null , [
4145 'label ' => 'widget_image.form.legend.label ' ,
4246 ])
43- ->add ('link ' , ' victoire_link ' , [
47+ ->add ('link ' , LinkType::class , [
4448 'required ' => false ,
4549 'horizontal ' => true ,
4650 ])
47- ->add ('hover ' , 'choice ' , [
48- 'label ' => 'widget_image.form.hover.label ' ,
49- 'attr ' => [
50- 'data-refreshOnChange ' => 'true ' ,
51+ ->add ('hover ' , ChoiceType::class, [
52+ 'label ' => 'widget_image.form.hover.label ' ,
53+ 'choices ' => [
54+ 'widget_image.form.hover.choice.default.label ' => 'default ' ,
55+ 'widget_image.form.hover.choice.popover.label ' => 'popover ' ,
56+ 'widget_image.form.hover.choice.tooltip.label ' => 'tooltip ' ,
5157 ],
52- 'choices ' => [
53- 'default ' => 'widget_image.form.hover.choice.default.label ' ,
54- 'popover ' => 'widget_image.form.hover.choice.popover.label ' ,
55- 'tooltip ' => 'widget_image.form.hover.choice.tooltip.label ' ,
58+ 'attr ' => [
59+ 'data-refreshOnChange ' => 'true ' ,
5660 ],
5761 ]);
5862
@@ -75,39 +79,36 @@ function (FormEvent $event) {
7579
7680 protected function manageRelativeFields (FormInterface $ form , $ hover )
7781 {
82+ $ positionChoices = [
83+ 'widget_image.form.placement.bottom ' => 'bottom ' ,
84+ 'widget_image.form.placement.left ' => 'left ' ,
85+ 'widget_image.form.placement.right ' => 'right ' ,
86+ 'widget_image.form.placement.top ' => 'top ' ,
87+ ];
88+
7889 if ($ hover == 'popover ' ) {
7990 $ form
8091 ->remove ('tooltip ' )
8192 ->add ('title ' , null , [
8293 'label ' => 'widget_image.form.title.popover.label ' ,
8394 ])
84- ->add ('popover ' , ' ckeditor ' , [
95+ ->add ('popover ' , CKEditorType::class , [
8596 'label ' => 'widget_image.form.popover.label ' ,
8697 'required ' => false ,
8798 ])
88- ->add ('placement ' , ' choice ' , [
99+ ->add ('placement ' , ChoiceType::class , [
89100 'label ' => 'widget_image.form.placement.label ' ,
90- 'choices ' => [
91- 'bottom ' => 'widget_image.form.placement.bottom ' ,
92- 'left ' => 'widget_image.form.placement.left ' ,
93- 'right ' => 'widget_image.form.placement.right ' ,
94- 'top ' => 'widget_image.form.placement.top ' ,
95- ],
101+ 'choices ' => $ positionChoices ,
96102 ]);
97103 } elseif ($ hover == 'tooltip ' ) {
98104 $ form
99105 ->remove ('popover ' )
100106 ->add ('title ' , null , [
101107 'label ' => 'widget_image.form.title.tooltip.label ' ,
102108 ])
103- ->add ('placement ' , ' choice ' , [
109+ ->add ('placement ' , ChoiceType::class , [
104110 'label ' => 'widget_image.form.placement.label ' ,
105- 'choices ' => [
106- 'bottom ' => 'widget_image.form.placement.bottom ' ,
107- 'left ' => 'widget_image.form.placement.left ' ,
108- 'right ' => 'widget_image.form.placement.right ' ,
109- 'top ' => 'widget_image.form.placement.top ' ,
110- ],
111+ 'choices ' => $ positionChoices ,
111112 ]);
112113 } else {
113114 $ form
@@ -121,11 +122,11 @@ protected function manageRelativeFields(FormInterface $form, $hover)
121122 }
122123
123124 /**
124- * @param OptionsResolverInterface $resolver
125+ * {@inheritdoc}
125126 */
126- public function setDefaultOptions ( OptionsResolverInterface $ resolver )
127+ public function configureOptions ( OptionsResolver $ resolver )
127128 {
128- parent ::setDefaultOptions ($ resolver );
129+ parent ::configureOptions ($ resolver );
129130
130131 $ resolver ->setDefaults (
131132 [
@@ -135,14 +136,4 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
135136 ]
136137 );
137138 }
138-
139- /**
140- * get form name.
141- *
142- * @return string The name of the form
143- */
144- public function getName ()
145- {
146- return 'victoire_widget_form_image ' ;
147- }
148139}
0 commit comments