Created
June 25, 2012 16:13
-
-
Save khepin/2989523 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\CommonBundle\Form\Type; | |
class GeoPointType extends AbstractType | |
{ | |
public function __construct($map) | |
{ | |
$this->map = $map->get('ivory_google_map.map'); | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder->appendClientTransformer(new GeoToLatLongTransformer); | |
} | |
public function getParent() | |
{ | |
return 'text'; | |
} | |
public function getName() | |
{ | |
return 'geo_point'; | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults([ | |
'widget' => 'geo_point', | |
'data_class' => 'Mashup\CommonBundle\Document\GeoPoint', | |
]); | |
} | |
public function buildView(FormViewInterface $view, FormInterface $form, array $options) | |
{ | |
$this->map->setStylesheetOption('width', '100%'); | |
$view->setVar('map', $this->map); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\CommonBundle\Form\DataTransformer; | |
class GeoToLatLongTransformer implements DataTransformerInterface | |
{ | |
public function transform($geo) | |
{ | |
return $geo->__toString(); | |
} | |
public function reverseTransform($latlong) | |
{ | |
return GeoPoint::createFromString($latlong); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acme.type.map: | |
class: Acme\CommonBundle\Form\Type\GeoPointType | |
arguments: [@service_container] | |
tags: | |
- { name: form.type, alias: geo_point } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment