I added a form event to my symphony form. The problem is that this event is removed twice when I'm debugging, then it goes two times in the method and I do not know why.
I have a form type that uses other form types. I have a VideoFileType form which is adding a field of image type. Both of these forms require some process after submitting the form once.
Image Type
& lt ;? Php # src / acme / PhotoBundle / Form / Type / Thumbnail Type. FTP Namespace OSC \ MediaBundle \ Form \ Type; Use OSC \ MediaBundle \ Manager / ImageManager; Use Symfony \ Component \ Dependency Injection \ Container; Use Symfony \ Component \ Form \ AbstractType; Use Symfony \ Component \ Form \ Extension \ Core \ ChoiceList \ ObjectChoiceList; Use Symfony \ Component \ Form \ FormBuilderInterface; Use Symfony \ Component \ Form \ FormEvent; Use Symfony \ Component \ Form \ FormEvents; Use Symfony \ Component \ HttpKernel \ Exception \ UnsupportedMediaTypeHttpException; Use Symfony \ Component \ OptionsResolver \ OptionsResolverInterface; Class ImageType Abertype {Personal $ Image Manager; Public Function __ Composition (ImageMenager $ Image Manager) {$ this- & gt; Image Manager = $ Image Manager; } Public Function buildForm (FormBuilderInterface $ builder, array $ option) {$ builder- & gt; Add ('file', 'file'); $ Manufacturer- & gt; Advert Listener (FormsEnglish :: POST_SUBMIT, array ($ this, 'onPostSetData')); } Public function getDefaultOptions (array $ option) {return array ('data_class' = & gt; 'OSC \ MediaBundle \ Entity \ Image'); } Public Function Set Default Options (OptionsResolverInterface $ Resolver) {$ resolver- & gt; Set Defaults (array ('data_class' = & gt; 'OSC \ MediaBundle \ Entity \ Image')); } Public Sending onPostSetData (FormEvent $ event) {$ image = $ event- & gt; GetData (); $ Form = $ event- & gt; GetForm (); // us new content $ image = $ this- & gt; ImageManager-> To update image file with upload image ($ image) here is required; $ Event & gt; SetData ($ image); } Public function getName () {return 'image'; }}
VideoFileType
& lt ;? Php # src / Acme / PhotoBundle / Form / Type / ThumbnailTipPFP Namespace OSS \ MediaBundle \ Form \ Type; Use OSC \ MediaBundle \ Manager \ VideoFileManager; Use Symfony \ Component \ Dependency Injection \ Container; Use Symfony \ Component \ Form \ AbstractType; Use Symfony \ Component \ Form \ Extension \ Core \ ChoiceList \ ObjectChoiceList; Use Symfony \ Component \ Form \ FormBuilderInterface; Use Symfony \ Component \ Form \ FormEvent; Use Symfony \ Component \ Form \ FormEvents; Class video file type abstraction type {expands public $ container; Public $ video presets = []; Public $ videofile manager; Public function __ composition (videofile manager $ videofile manager, container $ container) {$ this- & gt; Container = $ Container; $ Video presets = $ container- & gt; GetParameter ('osc_media.video.presets'); Forex Currency ($ $ as Video Practices => Video Presets as $ {$ }- {array_push ($ this-> Video Prites, $ Key); } $ This- & gt; VideoFile Manager = $ videoFileManager; } Public Function buildForm (FormBuilderInterface $ builder, array $ option) {$ builder- & gt; Add ('thumbnail', 'image'); $ Manufacturer- & gt; Add ('File', 'File'); $ Manufacturer- & gt; Add ('video preset', 'likes', array ('option' => $ this-> video prints, 'multiple' = & gt; wrong, 'required' => true)); $ Manufacturer- & gt; Advert Listener (FormsEnglish :: POST_SUBMIT, array ($ this, 'onPostSetData')); $ Manufacturer- & gt; Add ('Save', 'Submit'); } Public event onPostSetData (FormEvent $ event) {$ videoFile = $ event- & gt; GetData (); $ Form = $ event- & gt; GetForm (); // We video file $ videofile = $ this- & gt; VideoFile Manager- & gt; Upload Upload Video File ($ VideoFile); $ Event & gt; SetData ($ videofile); } Public function getDefaultOptions (array $ option) {Returns array ('data_class' = & gt; 'OSC \ MediaBundle \ Entity \ VideoFile'); } Public function getName () {Return 'video_file'; }}
I do not know why the onPostSetData method is called twice ...
< / Html>
No comments:
Post a Comment