Skip to content

Instantly share code, notes, and snippets.

@khepin
Created June 25, 2012 16:13
Show Gist options
  • Save khepin/2989523 to your computer and use it in GitHub Desktop.
Save khepin/2989523 to your computer and use it in GitHub Desktop.
<?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);
}
}
<?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);
}
}
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