First I defined GoogleMapType as a service in the app/config.yml :
services: # ... oh.GoogleMapFormType.form.type.googlemapformtype: class: Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType tags: - { name: form.type, alias: oh_google_maps }
I like noob with Symfony2, so I don’t know why for some reason the alias should be oh_google_maps .
Then I set the fields and functions to store latitude and longitude in the Entity class:
private $latlng; private $latitude; private $longitude; public function setLatlng($latlng) { $this->latlng = $latlng; $this->latitude = $latlng['lat']; $this->longitude = $latlng['lng']; return $this; } public function getLatLng() { return array('lat' => $this->latitude,'lng' => $this->longitude); }
Finally, in my regular Sonata Admin class, in the configureFormFields function:
protected function configureFormFields(FormMapper $formMapper) { $formMapper
source share