diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5657f6e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+vendor
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 17172fc..6192a72 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -2,34 +2,22 @@
namespace Oh\GoogleMapFormTypeBundle\DependencyInjection;
-
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
-/**
- * This is the class that validates and merges configuration from your app/config files
- *
- * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
- */
class Configuration implements ConfigurationInterface
{
- /**
- * {@inheritDoc}
- */
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('oh_google_map_form_type');
- // Here you should define the parameters that are allowed to
- // configure your bundle. See the documentation linked above for
- // more information on that topic.
$rootNode
->children()
- ->scalarNode('api_key')
+ ->scalarNode('api_key')->isRequired()->cannotBeEmpty()
->end()
- ->end();
+ ->end();
return $treeBuilder;
}
diff --git a/DependencyInjection/OhGoogleMapFormTypeExtension.php b/DependencyInjection/OhGoogleMapFormTypeExtension.php
index 0de5ae3..d7104bb 100644
--- a/DependencyInjection/OhGoogleMapFormTypeExtension.php
+++ b/DependencyInjection/OhGoogleMapFormTypeExtension.php
@@ -2,33 +2,19 @@
namespace Oh\GoogleMapFormTypeBundle\DependencyInjection;
+use Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-use Symfony\Component\DependencyInjection\Loader;
-/**
- * This is the class that loads and manages your bundle configuration
- *
- * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
- */
class OhGoogleMapFormTypeExtension extends Extension
{
- /**
- * {@inheritDoc}
- */
public function load(array $configs, ContainerBuilder $container)
{
- $configuration = new Configuration();
- $config = $this->processConfiguration($configuration, $configs);
-
-
- $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('services.xml');
-
- $container
- ->getDefinition('form.type.oh_google_maps')
- ->addArgument($config['api_key']);
+ $config = $this->processConfiguration(new Configuration(), $configs);
+ $container->register('form.type.oh_google_maps', GoogleMapType::class)
+ ->addArgument($config['api_key'])
+ ->addTag('form.type')
+ ;
}
}
diff --git a/Form/Type/GoogleMapType.php b/Form/Type/GoogleMapType.php
index 07f0437..a4ad314 100644
--- a/Form/Type/GoogleMapType.php
+++ b/Form/Type/GoogleMapType.php
@@ -4,7 +4,6 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
-use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
@@ -13,10 +12,10 @@
class GoogleMapType extends AbstractType
{
-
private $api_key;
- public function __construct($api_key){
+ public function __construct($api_key)
+ {
$this->api_key = $api_key;
}
@@ -92,16 +91,6 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['include_gmaps_js'] = $options['include_gmaps_js'];
}
- public function getParent()
- {
- return FormType::class;
- }
-
- public function getName()
- {
- return 'oh_google_maps';
- }
-
public function getBlockPrefix()
{
return 'oh_google_maps';
diff --git a/README.md b/README.md
index f08249d..835c4cf 100644
--- a/README.md
+++ b/README.md
@@ -21,17 +21,12 @@ public function registerBundles()
// ...
```
-You might need to change a couple of options if you are trying to use Symfony 2.0
-Add OhGoogleMapFormTypeBundle to assetic
-```yaml
-# app/config/config.yml
-# Assetic Configuration
-assetic:
- bundles: [ 'OhGoogleMapFormTypeBundle' ]
-
-...
+Add a file
+`vendor/oh/google-map-form-type-bundle/Oh/GoogleMapFormTypeBundle/Resources/public/js/jquery.ohgooglemaps.js`
+to your webpack encore config.
+```
oh_google_map_form_type:
api_key: "%google_maps_api_key%"
```
@@ -41,10 +36,19 @@ Usage
This bundle contains a new FormType called GoogleMapType which can be used in your forms like so:
- $builder->add('latlng', 'oh_google_maps');
+```php
+add('latlng', GoogleMapType::class);
+```
On your model you will have to process the latitude and longitude array
+```php
+
{% endblock %}
-
+```
Options
-------
There are a number of options, mostly self-explanatory
+```
array(
'type' => 'text', // the types to render the lat and lng fields as
'options' => array(), // the options for both the fields
@@ -116,6 +125,7 @@ There are a number of options, mostly self-explanatory
'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?
)
+```
Screenshots
-------
diff --git a/Resources/config/config.yml b/Resources/config/config.yml
deleted file mode 100644
index e69de29..0000000
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
deleted file mode 100644
index 2bf0328..0000000
--- a/Resources/config/services.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
- Oh\GoogleMapFormTypeBundle\Form\Type\GoogleMapType
-
-
-
-
-
-
-
-
-
diff --git a/Resources/views/Form/google_maps.html.twig b/Resources/views/Form/google_maps.html.twig
index 651cac2..2fb7f1c 100644
--- a/Resources/views/Form/google_maps.html.twig
+++ b/Resources/views/Form/google_maps.html.twig
@@ -20,16 +20,14 @@
{% endblock %}
{% block oh_google_maps_javascripts %}
{% if include_jquery %}
-
+
{% endif %}
{% if include_gmaps_js %}
{% endif %}
- {% javascripts
- '@OhGoogleMapFormTypeBundle/Resources/public/js/jquery.ohgooglemaps.js'
- %}
-
- {% endjavascripts %}
{% endblock %}
{% block oh_google_maps_javascript %}
{% block oh_google_maps_callback %}
diff --git a/composer.json b/composer.json
index 53a9759..40c8963 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,9 @@
],
"require": {
"php": ">=5.3.2",
- "symfony/framework-bundle": "^2.1 || ^3.0"
+ "symfony/framework-bundle": "^3.4 || ^4.1",
+ "symfony/form": "^3.4 || ^4.1",
+ "symfony/validator": "^3.4 || ^4.1"
},
"autoload": {
"psr-0": {