main: change address format for France, in Address render box and normalizer

This commit is contained in:
juminet
2021-12-12 15:05:54 +00:00
committed by Julien Fastré
parent b3929321b6
commit 898f25c0e4
4 changed files with 52 additions and 19 deletions

View File

@@ -46,6 +46,7 @@ class AddressRender implements ChillEntityRenderInterface
return $this->templating
->render('@ChillMain/Entity/address.html.twig', [
'address' => $addr,
'streetLine' => $this->renderStreetLine($addr),
'render' => $options['render'] ?? 'bloc',
'options' => $options,
]);
@@ -59,13 +60,7 @@ class AddressRender implements ChillEntityRenderInterface
{
$lines = [];
if (!empty($addr->getStreet())) {
$lines[0] = $addr->getStreet();
}
if (!empty($addr->getStreetNumber())) {
$lines[0] .= ', ' . $addr->getStreetNumber();
}
$lines[0] = $this->renderStreetLine($addr);
if (!empty($addr->getPostcode())) {
$lines[1] = strtr('{postcode} {label}', [
@@ -81,4 +76,33 @@ class AddressRender implements ChillEntityRenderInterface
{
return $entity instanceof Address;
}
private function renderStreetLine($addr): string
{
if (!empty($addr->getStreet())) {
$street = $addr->getStreet();
} else {
$street = '';
}
if (!empty($addr->getStreetNumber())) {
$streetNumber = $addr->getStreetNumber();
} else {
$streetNumber = '';
}
$res = trim($street . ', ' . $streetNumber, ', ');
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$res = trim($streetNumber . ', ' . $street, ', ');
}
}
if (',' === $res) {
$res = '';
}
return $res;
}
}