2017 © Pedro Peláez
 

symfony-bundle google-place-autocomplete-bundle

Provides a Google Place Autocomplete Type, the most minimalist, unobtrusive way possible.

image

cethyworks/google-place-autocomplete-bundle

Provides a Google Place Autocomplete Type, the most minimalist, unobtrusive way possible.

  • Sunday, August 20, 2017
  • by Cethy
  • Repository
  • 1 Watchers
  • 2 Stars
  • 579 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 37 % Grown

The README.md

Cethyworks\GooglePlaceAutocompleteBundle

Provides a Google Place Autocomplete Type, the most minimalist, unobtrusive way possible., (*1)

CircleCI, (*2)

Versions

For symfony >= 3.4

Use latest or >= v3.3, (*3)

For symfony < 3.4

Use 2.2 or lower, (*4)

Install

1. Composer require, (*5)

$ composer require cethyworks/google-place-autocomplete-bundle

2. Register bundles, (*6)

// 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 :, (*7)

cethyworks_google_place_autocomplete:
    google:
        api_key: 'your_api_key'

2. Use Cethyworks\GooglePlaceAutocompleteBundle\Form\SimpleGooglePlaceAutocompleteType into your forms ;, (*8)

3. Done !, (*9)

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., (*10)

Instead of returning a simple string, this Type return a Cethyworks\GooglePlaceAutocompleteBundle\Model\Place object., (*11)

In order to persist it, the bundle provides doctrine mapping, use it like this in your entities :, (*12)

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., (*13)

Additional information

Cethyworks\ContentInjectorBundle, (*14)

Google Place Autocomplete Documentation, (*15)

Roadmap

  • Update README.md with a example transforming Place into another entity
  • Update Place entity to retrieve more data

The Versions