cethyworks / google-place-autocomplete-bundle
Provides a Google Place Autocomplete Type, the most minimalist, unobtrusive way possible.
Installs: 10 679
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 10
Open Issues: 4
Type:symfony-bundle
Requires
- php: ^7.1.3
- cethyworks/content-injector-bundle: ^3.0|^5.0
- symfony/config: ^3.4|~4.2|^5.0
- symfony/dependency-injection: ^3.4|^4.2|^5.0
- symfony/form: ^3.4|^4.2|^5.0
- twig/twig: ^1.0||^2.0|^5.0
Requires (Dev)
- phpunit/phpunit: ^4.8
- symfony/asset: ^3.4|^4.2|^5.0
- symfony/event-dispatcher: ^3.4|^4.2|^5.0
- symfony/framework-bundle: ^3.4|~4.0|^5.0
- symfony/http-foundation: ^3.4|^4.2|^5.0
- symfony/http-kernel: ^3.4|^4.2|^5.0
- symfony/templating: ^3.4|^4.2|^5.0
- symfony/translation: ^3.4|^4.2|^5.0
- symfony/twig-bundle: ^3.4|^4.2|^5.0
- symfony/validator: ^3.4|^4.2|^5.0
README
Provides a Google Place Autocomplete Type, the most minimalist, unobtrusive way possible.
Versions
For symfony >= 3.4
Use latest or >= v3.3
For symfony < 3.4
Use 2.2 or lower
Install
1. Composer require
$ composer require cethyworks/google-place-autocomplete-bundle
2. Register bundles
// AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Cethyworks\ContentInjectorBundle\CethyworksContentInjectorBundle(),
new Cethyworks\GooglePlaceAutocompleteBundle\CethyworksGooglePlaceAutocompleteBundle(),
];
// ...
How to use
1. Add (optionally) a config/packages/cethyworks_google_place_autocomplete.yaml
file with :
cethyworks_google_place_autocomplete:
google:
api_key: 'your_api_key'
2. Use Cethyworks\GooglePlaceAutocompleteBundle\Form\SimpleGooglePlaceAutocompleteType
into your forms ;
3. Done !
Get more data from the Google Place API
If you need more info from the place API results, you can use the ComplexGooglePlaceAutocompleteType
in your forms instead.
Instead of returning a simple string
, this Type return a Cethyworks\GooglePlaceAutocompleteBundle\Model\Place
object.
In order to persist it, the bundle provides doctrine mapping, use it like this in your entities :
use Cethyworks\GooglePlaceAutocompleteBundle\Model\Place;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="dummy_entity")
* @ORM\Entity()
*/
class DummyEntity
{
/**
* @var Place
*
* @ORM\Embedded(class="Cethyworks\GooglePlaceAutocompleteBundle\Model\Place")
*
* @Assert\NotBlank()
*/
private $locationAddress;
// ...
}
How it works
When either a SimpleGooglePlaceAutocompleteType
or a ComplexGooglePlaceAutocompleteType
are used,
it registers 2 InjectorCommands
(one for the library call, one for the input controls)
which will inject the necessary javascript code (with the input id & the google api_key) into the Response
automatically.
Additional information
Cethyworks\ContentInjectorBundle
Google Place Autocomplete Documentation
Roadmap
- Update README.md with a example transforming Place into another entity
- Update Place entity to retrieve more data