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

0.08 2025-11-22 13:47 UTC

This package is auto-updated.

Last update: 2025-11-24 18:51:31 UTC


README

AddressBundle

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

Cmrweb/RequestBundle

.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;