cmrweb / address-bundle
api.gouv symfony helper
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/cmrweb/address-bundle
Requires
- cmrweb/request-bundle: ^0.02.0
- phpdocumentor/reflection-docblock: ^5.6
- phpstan/phpdoc-parser: ^2.3
- symfony/asset: ^7.3
- symfony/asset-mapper: ^7.3
- symfony/console: ^7.3
- symfony/dotenv: ^7.3
- symfony/flex: ^2.10
- symfony/framework-bundle: ^7.3
- symfony/http-client: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/property-info: ^7.3
- symfony/runtime: ^7.3
- symfony/serializer: ^7.3
- symfony/twig-bundle: ^7.3
- symfony/ux-live-component: ^2.31
- symfony/yaml: ^7.3
- twig/extra-bundle: ^2.12|^3.0
- twig/twig: ^2.12|^3.0
Requires (Dev)
- phpunit/phpunit: ^12.4
- symfony/browser-kit: ^7.3
- symfony/css-selector: ^7.3
- symfony/dom-crawler: ^7.3
- symfony/phpunit-bridge: ^7.3
README
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and execute:
composer require cmrweb/address-bundle
Applications that don't use Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require cmrweb/address-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
return [ Cmrweb\AddressBundle\AddressBundle::class => ['all' => true], ];
Config
.env
###> cmrweb/address-bundle ### API_ADDRESS="https://data.geopf.fr/" ###< cmrweb/address-bundle ###
config/services.yaml
parameters: # ... cmrweb.api.address: '%env(API_ADDRESS)%' services: # ... Cmrweb\AddressBundle\Service\ApiAddressService: arguments: $url: '%cmrweb.api.address%'
Usage
Display autocompletion input
Make Symfony live-component
symfony console make:twig-component --live
Use SearchAddressTrait in your component
// ... use DefaultActionTrait; use SearchAddressTrait;
Edit your component.html.twig
<!-- without css --> <div {{attributes}} data-loading="addClass(opacity-80) addAttribute(disabled)"> <input type="text" placeholder="address" autocomplete="false" spellcheck="false" {{ live_action('setAddressLabel', {event:'input', debounce: 1000}) }} data-model="addressLabel"> <ul> {% for key, completion in autocompletions %} <li> <button type="button" {{live_action('selectCompletion', {key: key})}}> {{completion.fulltext}} </button> </li> {% endfor %} </ul> </div>
<!-- bootstrap --> <div {{attributes}} data-loading="addClass(opacity-80) addAttribute(disabled)" class="input-goup"> <input type="text" placeholder="address" class="form-control" autocomplete="false" spellcheck="false" {{ live_action('setAddressLabel', {event:'input', debounce: 1000}) }} data-model="addressLabel"> <ul class="list-group"> {% for key, completion in autocompletions %} <li class="list-group-item"> <button type="button" {{live_action('selectCompletion', {key: key})}} class="btn border-0 w-100 text-start"> {{completion.fulltext}} </button> </li> {% endfor %} </ul> </div>
Get Address
Return Address Model with AddressTrait in same or other component.
// ... use AddressTrait; // ... # return Address Model $this->getAddress() # return Address array $this->getAddressArray()
Twig
{{ dump(address) }}
{{ dump(addressArray) }}
Address Model
string $label; string $numero; string $libelle; string $codePostal; string $ville; string $region; float $lat; float $lon; public function getLabel(): string; public function getNumero(): string; public function getLibelle(): string; public function getCodePostal(): string; public function getVille(): string; public function getRegion(): string; public function getLat(): float; public function getLon(): float;