Skip to content

Commit

Permalink
Fixed review comments, rename form type
Browse files Browse the repository at this point in the history
  • Loading branch information
daften committed Aug 6, 2020
1 parent 5dba92f commit 2939004
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* A form used to have an Embeddable Address form with autocomplete with Gmaps.
*/
class AddressGmapsAutocompleteEmbeddableType extends AbstractType
class AddressEmbeddableGmapsAutocompleteType extends AbstractType
{

/**
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
[![Build Status](https://travis-ci.org/daften/addressing-bundle.svg?branch=develop)](https://travis-ci.org/daften/addressing-bundle)
[![Maintainability](https://api.codeclimate.com/v1/badges/c8d0411c6ae51c1f1119/maintainability)](https://codeclimate.com/github/daften/addressing-bundle/maintainability)

## Requirements

* jQuery loaded as $
* jQuery Once loaded properly.

## Installation

Add the mapping to your doctrine.yaml file:
Expand Down Expand Up @@ -36,7 +41,7 @@ var countryCodeChange = require('../../public/bundles/addressing/js/countryCodeC
countryCodeChange.initialize();
```

### AddressGmapsAutocompleteEmbeddableType
### AddressEmbeddableGmapsAutocompleteType

You'll also need to add some javascript code, to make sure the autocomplete functionality works.

Expand Down Expand Up @@ -167,13 +172,13 @@ class AddressExampleType extends AbstractType
}
```

#### AddressGmapsAutocompleteEmbeddableType
#### AddressEmbeddableGmapsAutocompleteType

There is 1 additional option that can be used for this form type:
* allowed_countries: The countries allowed for autocompletion. An array where the values should be the 2-character
country code.

An example form for the AddressExample class given above using the AddressGmapsAutocompleteEmbeddableType with one
An example form for the AddressExample class given above using the AddressEmbeddableGmapsAutocompleteType with one
autocomplete field.

```php
Expand All @@ -182,7 +187,7 @@ autocomplete field.
namespace App\Form;
use App\Entity\AddressExample;
use Daften\Bundle\AddressingBundle\Form\Type\AddressGmapsAutocompleteEmbeddableType;
use Daften\Bundle\AddressingBundle\Form\Type\AddressEmbeddableGmapsAutocompleteType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -198,7 +203,7 @@ class AddressExampleType2 extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('address', AddressGmapsAutocompleteEmbeddableType::class, [
->add('address', AddressEmbeddableGmapsAutocompleteType::class, [
'label' => 'address',
'translation_domain' => 'address',
'allowed_countries' => [
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ services:
- form.type

daften.form.type.address_autocomplete_gmaps:
class: Daften\Bundle\AddressingBundle\Form\Type\AddressGmapsAutocompleteEmbeddableType
class: Daften\Bundle\AddressingBundle\Form\Type\AddressEmbeddableGmapsAutocompleteType
arguments:
- '@Daften\Bundle\AddressingBundle\Service\GmapsAutocompleteService'
- '@daften.service.gmaps_autocomplete_service'
public: false
tags:
- form.type
Expand Down
5 changes: 4 additions & 1 deletion Service/GmapsAutocompleteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function setGmapsApiKey(string $gmapsApiKey): void
$this->gmapsApiKey = $gmapsApiKey;
}

public function addressAutocompleteDefault(AddressEmbeddable $address) {
public function addressAutocompleteDefault(AddressEmbeddable $address): string
{
$countries = $this->countryRepository->getAll();
$address_default = implode(', ', array_filter([
$address->getRecipient(),
Expand All @@ -73,6 +74,8 @@ public function addressAutocompleteDefault(AddressEmbeddable $address) {
$address->getPostalCode().' '.$address->getLocality(),
$countries[$address->getCountryCode()]->getName(),
]));

return $address_default;
}

}

0 comments on commit 2939004

Please sign in to comment.