Hello!

In buildForm i'm calling the googlemap field type which is a custom field 
(called by service container) type with 3 fields into:

$builder
            
->add('gmap_position','googlemap',array('dbrow'=>$builder->getData(),'mapsettings'=>array('map_id'=>'map_canvas','width'=>'600px','height'=>'400px')))
            ->add('text','ckeditor')
            ->add('status','status')
        ;

The google map field type is here - i'm adding 3 fields in the form builder 
- but get the error 

You cannot add children to a simple form. Maybe you should set the option 
"compound" to true?

<?php

namespace Mediauna\AdminBundle\Form\FieldTypes;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface;
use Ivory\GoogleMapBundle\Model\MapTypeId;
use Ivory\GoogleMapBundle\Model\Map;

class GoogleMapType extends AbstractType {

    private $map;
    private $event;
    private $doctrine;
    
    public function __construct(ContainerInterface $service) {
        $this->map = $service->get('ivory_google_map.map');
        $this->mapEvent = $service->get('ivory_google_map.event');
        $this->doctrine = $service->get('doctrine');
    }

    public function getDefaultOptions(array $options) {
        return array('mapsettings' => array(
                'map_id' => 'map_canvas',
                'width' => '600px',
                'height' => '400px',
            ),
            'dbrow' => array()
        );
    }

    public function buildForm(FormBuilderInterface $builder, array 
$options) {
        $builder
*            ->add('gmap_position', new HiddenType())*
*            ->add('gmap_center', new HiddenType())*
*            ->add('gmap_zoomlevel', new HiddenType())*
        ;
    }

    public function buildView(FormView $view, FormInterface $form, array 
$options) {
        parent::buildView($view, $form, $options);

        $mapSettings = $options['mapsettings'];
        
        /** @var $map Ivory\GoogleMapBundle\Model\Map */
        $map = $this->map;

        // Configure your map options
        $map->setPrefixJavascriptVariable('map_');
        $map->setHtmlContainerId('map_canvas');

        $map->setAsync(true);

        $map->setAutoZoom(false);

        $map->setCenter(20, 20, true);
        $map->setMapOption('zoom', 2);

        $map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);

        $map->setMapOption('mapTypeId', MapTypeId::SATELLITE);

        $map->setMapOption('disableDefaultUI', true);
        $map->setMapOption('disableDoubleClickZoom', true);
        $map->setMapOptions(array(
            'disableDefaultUI' => false,
            'disableDoubleClickZoom' => true
        ));
        
        // Configure your event
        $event = $this->mapEvent;
        $event->setInstance($map->getJavascriptVariable());
        $event->setEventName('click');
        
        $handle = '
            function(e) { 
                var marker = new google.maps.Marker({position: 
e.latLng,map: '.$map->getJavascriptVariable().'});
                '.$map->getJavascriptVariable().'_clearOverlays();
                '.$map->getJavascriptVariable().'_markers.pop(0);
                '.$map->getJavascriptVariable().'_markers.push(marker);
                
$("#'.$map->getJavascriptVariable().'_position").val(e.latLng.lat()+","+e.latLng.lng());
            }
        ';
        
        $event->setHandle($handle);
        
        // It can only be used with a DOM event
        // By default, the capture flag is false
        $event->setCapture(true);
        $map->getEventManager()->addDomEvent($event);

        
        
        $map->setLanguage('en');
        $view->vars['map'] = $map;

        $view->vars['map_js_variable'] = $map->getJavascriptVariable();
        $view->vars['width'] = $mapSettings['width'];
        $view->vars['height'] = $mapSettings['height'];
        $view->vars['map_id'] = $mapSettings['map_id'];
        
        $dbrow = $options['dbrow'];
        
        #$view->vars['map_center'] = $dbrow->getGmapCenter();
        #$view->vars['map_position'] = $dbrow->getGmapPosition();
        #$view->vars['map_zoomlevel'] = $dbrow->getGmapZoomlevel();
    }

    public function getParent() {
        return 'text';
    }

    public function getName() {
        return 'googlemap';
    }

}

Any suggenstions to get the children field with 3 fields to work?

Thank you 

Claus

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to