Example #1
0
 protected function configureFormFields(FormMapper $formMapper)
 {
     $formMapper->with('Общая информация', array('class' => 'col-md-6'))->add('type', 'choice', array('choices' => Content::getTypes(), 'expanded' => false, 'label' => 'Тип блока'))->add('name', 'text', array('label' => 'Название'))->add('link', 'text', array('label' => 'Ссылка с названия', 'required' => false))->end();
     $subject = $this->getSubject();
     if ($subject->getId() == NULL) {
         $horizontal = false;
     } else {
         $horizontal = $subject->getHorizontal();
     }
     switch ($subject->getType()) {
         case 'gallery':
             $formMapper->with('Взаимосвязь', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false, 'label' => 'Блок расположен на странице'))->add('order_column', 'integer', array('label' => 'Порядок', 'help' => 'Чем меньше, тем выше на странице будет расплоложено содержимое'))->add('gallery', 'sonata_type_model_list', array('btn_add' => false, 'label' => 'Галерея'))->add('horizontal', 'checkbox', array('data' => $horizontal, 'required' => false, 'label' => 'Горизонтальное ориентирование блока'))->end()->with('Контент', array('class' => 'col-md-12'))->add('content', 'ckeditor', array('config_name' => 'default', 'label' => 'Текст'))->end();
             break;
         case 'video':
         case 'content':
             $formMapper->with('Взаимосвязь', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false, 'label' => 'Блок расположен на странице'))->add('order_column', 'integer', array('label' => 'Порядок', 'help' => 'Чем меньше, тем выше на странице будет расплоложено содержимое'))->add('gallery', 'sonata_type_model_list', array('btn_add' => false, 'label' => 'Галерея'))->end()->with('Контент', array('class' => 'col-md-12'))->add('content', 'ckeditor', array('config_name' => 'default', 'label' => 'Текст'))->end();
             break;
         case 'slider':
             $formMapper->with('General', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false))->add('order_column')->end()->with('Slider', array('class' => 'col-md-12'))->add('teams', 'sonata_type_collection', array('by_reference' => false, 'cascade_validation' => true), array('edit' => 'inline', 'inline' => 'table'))->end();
             break;
         case 'photo':
         case 'video_gallery':
             $formMapper->with('General', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false))->add('order_column')->add('gallery', 'sonata_type_model_list', array('btn_add' => false))->end();
             break;
         case 'contacts':
             $formMapper->with('General', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false))->add('order_column')->end()->with('Contacts', array('class' => 'col-md-12'))->add('contacts', 'sonata_type_collection', array('by_reference' => false, 'cascade_validation' => true), array('edit' => 'inline', 'inline' => 'standard'))->end();
             break;
         case 'stuff':
             $formMapper->with('General', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false))->add('order_column')->add('stuff', 'choice', array('choices' => Stuff::getTypes(), 'expanded' => true))->end();
             break;
         case 'news':
             $formMapper->with('General', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false))->add('order_column')->end();
             break;
         case 'photo_links':
             $formMapper->with('General', array('class' => 'col-md-6'))->add('url', 'sonata_type_model_list', array('btn_add' => false))->add('order_column')->end();
             break;
         default:
             break;
     }
     //выбор меню второго уровня если есть контент для этого
     //if ($subject->getUrl() != null && count($subject->getUrl()->getChildren()) > 1) {
     /*if ($subject->getUrl() != null) {
           $choices = array();
           //dump();die();
           foreach($subject->getUrl()->getChildren() as $index => $value){
               $choices[$value->getId()] = $value->getTitle();
           }
           if(count($choices)>1){
               $choices[0] = 'Все меню';
           }
           $choices[-1] = 'Отключить';
           $formMapper
               ->with('secondMenu', array('class' => 'col-md-6'))
                   ->add('second_menu', 'choice', array('choices' => $choices, 'expanded' => true))
               ->end();
       }*/
     // работает норм только после update
     //$em = $this->modelManager->getEntityManager('Application\Sonata\MediaBundle\Entity\Gallery');
     //$currentUrl = $em->getRepository('SonataMediaBundle:Gallery')->findAll();
     //$currentUrl = $em->getRepository('ApplicationSonataMediaBundle:Gallery')->findOneBy(array('id'=>4));
     //echo "<pre>";var_dump($currentUrl);die();
     //->add('gallery_id', 'sonata_type_model_list', array('class' => 'Sonata\MediaBundle\Entity\Gallery'), array('placeholder' => 'qweqwe'))
     //->add('gallery_id', 'choice', array('choices' => $this->getGalleries(), 'expanded' => true))
     //            ->add('media', 'sonata_media_type', array(
     //                 'provider' => 'sonata.media.provider.image',
     //                 'context'  => 'engine'
     //            ));
     //        $subject = $this->getSubject();
     //
     //        if ($subject->isNew()) {
     //            // The thumbnail field will only be added when the edited item is created
     //            $formMapper->add('thumbnail', 'file');
     //        }
 }
Example #2
0
 protected function configureFormFields(FormMapper $formMapper)
 {
     //        $builder = $formMapper->getFormBuilder();
     //
     //
     //
     //
     //        $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
     //            $product = $event->getData();
     //
     //            if ($product && $product->getType() == 'gallery') {
     //                $form->add('gallery');
     //            }else{
     //                $form->add('name');
     //            }
     //        });
     //        $subject = $this->getSubject();
     //        //dump($subject);die();
     //        if ($subject->getType() == 'gallery') {
     //            // The thumbnail field will only be added when the edited item is created
     //            $formMapper->add('gallery');
     //        }
     $formMapper->with('Important', array('class' => 'col-md-6'))->add('type', 'choice', array('choices' => Content::getTypes(), 'expanded' => false))->add('name')->end();
     $formModifier = function (FormInterface $form, Content $content = null) {
         $form->add('url');
     };
     //
     //$admin = $this;
     $formMapper->getFormBuilder()->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formModifier) {
         //$data = $event->getData();
         $formModifier($event->getForm(), $this->getSubject($event->getData()));
     });
     $formMapper->getFormBuilder()->get('type')->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use($formModifier) {
         // It's important here to fetch $event->getForm()->getData(), as
         // $event->getData() will get you the client data (that is, the ID)
         //$info = $event->getForm()->getData();
         // since we've added the listener to the child, we'll have to pass on
         // the parent to the callback functions!
         $formModifier($event->getForm()->getParent());
     });
     //
     ///----------------
     //        $formMapper
     //            ->with('Important', array('class' => 'col-md-6'))
     //                ->add('type', 'choice', array('choices' => Content::getTypes(), 'expanded' => true))
     //                ->add('name')
     //            ->end()
     //            ->with('General', array('class' => 'col-md-6'))
     //                ->add('url')
     //                ->add('top_menu', null, array('required' => false))
     //                ->add('order_column')
     //                ->add('gallery')
     //            ->end()
     //            ->with('Content', array('class' => 'col-md-12'))
     //                ->add('content', 'ckeditor',array('config_name' => 'default'))
     //            ->end()
     $subject = $this->getSubject();
     //выбор меню второго уровня если есть контент для этого
     //if ($subject->getUrl() != null && count($subject->getUrl()->getChildren()) > 1) {
     if ($subject->getUrl() != null) {
         $choices = array();
         foreach ($subject->getUrl()->getChildren() as $index => $value) {
             $choices[$index + 1] = $value->getTitle();
         }
         //            if(count($choices)>1){
         //                $choices[0] = 'Все меню';
         //            }
         $choices[-1] = 'Отключить';
         $formMapper->with('secondMenu', array('class' => 'col-md-6'))->add('second_menu', 'choice', array('choices' => $choices, 'expanded' => true))->end();
     }
     if ($subject->getType() == 'slider') {
         $formMapper->with('Slider', array('class' => 'col-md-12'))->add('teams', 'sonata_type_collection', array('by_reference' => false, 'cascade_validation' => true), array('edit' => 'inline', 'inline' => 'table'))->end();
     }
     // работает норм только после update
     //$em = $this->modelManager->getEntityManager('Application\Sonata\MediaBundle\Entity\Gallery');
     //$currentUrl = $em->getRepository('SonataMediaBundle:Gallery')->findAll();
     //$currentUrl = $em->getRepository('ApplicationSonataMediaBundle:Gallery')->findOneBy(array('id'=>4));
     //echo "<pre>";var_dump($currentUrl);die();
     //->add('gallery_id', 'sonata_type_model_list', array('class' => 'Sonata\MediaBundle\Entity\Gallery'), array('placeholder' => 'qweqwe'))
     //->add('gallery_id', 'choice', array('choices' => $this->getGalleries(), 'expanded' => true))
     //            ->add('media', 'sonata_media_type', array(
     //                 'provider' => 'sonata.media.provider.image',
     //                 'context'  => 'engine'
     //            ));
     //        $subject = $this->getSubject();
     //
     //        if ($subject->isNew()) {
     //            // The thumbnail field will only be added when the edited item is created
     //            $formMapper->add('thumbnail', 'file');
     //        }
 }