Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 4777a4c5a0
Fetching contributors…

Cannot retrieve contributors at this time

57 lines (46 sloc) 1.504 kB
<?php
/*
* This file is part of the GenemuFormBundle package.
*
* (c) Olivier Chauvel <olivier@generation-multiple.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Genemu\Bundle\FormBundle\Form\Core\EventListener;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Event\DataEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Genemu\Bundle\FormBundle\Geolocation\AddressGeolocation;
/**
* GeoListener
*
* @author Olivier Chauvel <olivier@generation-multiple.com>
*/
class GeolocationListener implements EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public function onBindNormData(DataEvent $event)
{
$data = $event->getData();
if (empty($data)) {
return;
}
$address = $data['address'];
$latitude = isset($data['latitude']) ? $data['latitude'] : null;
$longitude = isset($data['longitude']) ? $data['longitude'] : null;
$locality = isset($data['locality']) ? $data['locality'] : null;
$country = isset($data['country']) ? $data['country'] : null;
$geo = new AddressGeolocation($address, $latitude, $longitude, $locality, $country);
$event->setData($geo);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(FormEvents::BIND_NORM_DATA => 'onBindNormData');
}
}
Jump to Line
Something went wrong with that request. Please try again.