diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9a273b6..3a6486d 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -18,9 +18,16 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
- $treeBuilder = new TreeBuilder();
+ $treeBuilder = new TreeBuilder('oh_google_map_form_type');
- $rootNode = $treeBuilder->root('oh_google_map_form_type');
+ $rootNode = $treeBuilder->getRootNode();
+
+
+ $rootNode
+ ->children()
+ ->scalarNode('api_key')->defaultNull()->end()
+ ->scalarNode('include_gmaps_js')->defaultFalse()->end()
+ ->end();
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
diff --git a/Form/Type/GoogleMapType.php b/Form/Type/GoogleMapType.php
index 25cbe22..2fe4263 100755
--- a/Form/Type/GoogleMapType.php
+++ b/Form/Type/GoogleMapType.php
@@ -1,13 +1,21 @@
add($options['lat_name'], $options['type'], array_merge($options['options'], $options['lat_options']))
- ->add($options['lng_name'], $options['type'], array_merge($options['options'], $options['lng_options']))
- ;
+
+ unset($options['options']['compound']);
+
+ if($options['editable'])
+ $builder
+ ->add($options['lat_name'], HiddenType::class, array_merge($options['options'], $options['lat_options']))
+ ->add($options['lng_name'],HiddenType::class, array_merge($options['options'], $options['lng_options']))
+ ;
+
+ else{
+
+ $entity = $builder->getData();
+
+ ErrorService::getInstance()->addDebug($builder);
+
+ $builder
+ ->add($options['lat_name'],HiddenType::class, array_merge($options['options'], $options['lat_options']))
+ ->add($options['lng_name'], HiddenType::class, array_merge($options['options'], $options['lng_options']))
+// ->add('Coordinates',StringType::class,[
+// 'data'=>'sdfdfs',
+// 'required'=>false,
+// 'mapped'=>false,
+// ])
+ ;
+
+ }
}
/**
* {@inheritdoc}
*/
- public function setDefaultOptions(OptionsResolverInterface $resolver)
+ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
- 'type' => 'text', // the types to render the lat and lng fields as
- 'options' => array(), // the options for both the fields
+ 'editable' => true,
+ 'type' => TextType::class, // the types to render the lat and lng fields as
+ 'compound'=>true,
+ 'options' => array(
+ 'compound'=>true
+ ), // the options for both the fields
'lat_options' => array(), // the options for just the lat field
'lng_options' => array(), // the options for just the lng field
'lat_name' => 'lat', // the name of the lat field
'lng_name' => 'lng', // the name of the lng field
'error_bubbling' => false,
+ 'zoom_callback' => false, //form callback
'map_width' => 300, // the width of the map
'map_height' => 300, // the height of the map
- 'default_lat' => 51.5, // the starting position on the map
- 'default_lng' => -0.1245, // the starting position on the map
+ 'default_lat' => AppConfig::LOCATION_DEFAULT_LAT, // the starting position on the map
+ 'default_lng' => AppConfig::LOCATION_DEFAULT_LNG, // the starting position on the map
+ 'default_zoom' => AppConfig::LOCATION_DEFAULT_ZOOM, // the starting position on the map
'include_jquery' => false, // jquery needs to be included above the field (ie not at the bottom of the page)
'include_gmaps_js'=>true // is this the best place to include the google maps javascript?
));
@@ -51,23 +87,31 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
- $view->vars['lat_name'] = $options['lat_name'];
- $view->vars['lng_name'] = $options['lng_name'];
- $view->vars['map_width'] = $options['map_width'];
- $view->vars['map_height'] = $options['map_height'];
- $view->vars['default_lat'] = $options['default_lat'];
- $view->vars['default_lng'] = $options['default_lng'];
- $view->vars['include_jquery'] = $options['include_jquery'];
- $view->vars['include_gmaps_js'] = $options['include_gmaps_js'];
+ $view->vars['editable'] = $options['editable'];
+ $view->vars['lat_name'] = $options['lat_name'];
+ $view->vars['lng_name'] = $options['lng_name'];
+ $view->vars['map_width'] = $options['map_width'];
+ $view->vars['map_height'] = $options['map_height'];
+ $view->vars['default_lat'] = $options['default_lat'];
+ $view->vars['default_lng'] = $options['default_lng'];
+ $view->vars['default_zoom'] = $options['default_zoom'];
+ $view->vars['include_jquery'] = $options['include_jquery'];
+ $view->vars['include_gmaps_js'] = $options['include_gmaps_js'];
+ $view->vars['zoom_callback'] = $options['zoom_callback'];
+
+
+
+
}
public function getParent()
{
- return 'form';
+ return TextType::class;
}
- public function getName()
+ public function getBlockPrefix()
{
- return 'oh_google_maps';
+ return 'oh_google_maps';
+
}
}
diff --git a/README.md b/README.md
index 28c09ac..e905d4c 100755
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Installation
This bundle is compatible with Symfony 2.1. Add the following to your `composer.json`:
- "oh/google-map-form-type-bundle": "dev-master"
+ "grekpg/OhGoogleMapFormTypeBundle": "dev-master"
Register the bundle in your `app/AppKernel.php`:
@@ -36,7 +36,9 @@ Usage
This bundle contains a new FormType called GoogleMapType which can be used in your forms like so:
- $builder->add('latlng', 'oh_google_maps');
+ $builder->add('latlng', GoogleMapType::class,array(
+ 'zoom_callback'=>'function(zoom){ $("#zoom").val(zoom); }' //optional zoom change listener
+ ));
On your model you will have to process the latitude and longitude array
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
index 6cac9f7..f9343a7 100644
--- a/Resources/config/services.xml
+++ b/Resources/config/services.xml
@@ -12,6 +12,7 @@