mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch 'period-in-list-result' into 59_parcours_resu_2
This commit is contained in:
@@ -9,6 +9,12 @@ div.chill_address {
|
||||
margin: 0 0 0 1.5em;
|
||||
text-indent: -1.5em;
|
||||
}
|
||||
|
||||
&.chill_address_address--multiline {
|
||||
p {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,11 @@ ul.record_actions li {
|
||||
ul.record_actions, ul.record_actions_column {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
&.record_actions--left {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
padding: 0.5em 0;
|
||||
flex-wrap: wrap-reverse;
|
||||
|
||||
|
@@ -0,0 +1,16 @@
|
||||
<div class="chill_address">
|
||||
{% if options['has_no_address'] == true and address.isNoAddress == true %}
|
||||
<div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div>
|
||||
{% endif %}
|
||||
<div class="chill_address_address {% if options['multiline'] %}chill_address_address--multiline{% endif %}">
|
||||
{% if address.street is not empty %}<p class="street street1">{{ address.street }}</p>{% endif %}
|
||||
{% if address.streetNumber is not empty %}<p class="street street2">{{ address.streetNumber }}</p>{% endif %}
|
||||
{% if address.postCode is not empty %}
|
||||
<p class="postalCode"><span class="code">{{ address.postCode.code }}</span> <span class="name">{{ address.postCode.name }}</span></p>
|
||||
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- if options['with_valid_from'] == true -%}
|
||||
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}</span>
|
||||
{%- endif -%}
|
||||
</div>
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
|
||||
class AddressRender implements ChillEntityRenderInterface
|
||||
{
|
||||
private EngineInterface $templating;
|
||||
|
||||
public const DEFAULT_OPTIONS = [
|
||||
'with_valid_from' => true,
|
||||
'has_no_address' => false,
|
||||
'multiline' => true,
|
||||
];
|
||||
|
||||
public function __construct(EngineInterface $templating)
|
||||
{
|
||||
$this->templating = $templating;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function supports($entity, array $options): bool
|
||||
{
|
||||
return $entity instanceof Address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address addr
|
||||
*/
|
||||
public function renderString($addr, array $options): string
|
||||
{
|
||||
$lines = [];
|
||||
if (!empty($addr->getStreet())) {
|
||||
$lines[0] = $addr->getStreet();
|
||||
}
|
||||
if (!empty($addr->getStreetNumber())) {
|
||||
$lines[0] .= ", ".$addr->getStreetNumber();
|
||||
}
|
||||
if (!empty($addr->getPostcode())) {
|
||||
$lines[1] = \strtr("{postcode} {label}", [
|
||||
'{postcode}' => $addr->getPostcode()->getCode(),
|
||||
'{label}' => $addr->getPostcode()->getName()
|
||||
]);
|
||||
}
|
||||
|
||||
return implode(" - ", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param Address addr
|
||||
*/
|
||||
public function renderBox($addr, array $options): string
|
||||
{
|
||||
$options = \array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
return $this->templating
|
||||
->render('@ChillMain/Address/entity_render.html.twig', [
|
||||
'address' => $addr,
|
||||
'options' => $options
|
||||
]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Tests\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\Country;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\Templating\Entity\AddressRender;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
class AddressRenderTest extends KernelTestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
self::bootKernel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider addressDataProvider
|
||||
*/
|
||||
public function testRenderString(Address $addr, string $expectedString): void
|
||||
{
|
||||
$engine = self::$container->get(EngineInterface::class);
|
||||
$renderer = new AddressRender($engine);
|
||||
|
||||
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
|
||||
return;
|
||||
$this->assertIsString($renderer->renderBox($addr, []));
|
||||
}
|
||||
|
||||
|
||||
public function addressDataProvider(): \Iterator
|
||||
{
|
||||
$addr = new Address();
|
||||
$country = (new Country())
|
||||
->setName([ "fr" => "Pays" ])
|
||||
->setCountryCode("BE")
|
||||
;
|
||||
$postCode = new PostalCode();
|
||||
$postCode->setName("Locality")
|
||||
->setCode("012345")
|
||||
->setCountry($country)
|
||||
;
|
||||
|
||||
$addr->setStreet("Rue ABC")
|
||||
->setStreetNumber("5")
|
||||
->setPostcode($postCode)
|
||||
;
|
||||
|
||||
yield[ $addr, "Rue ABC, 5 - 012345 Locality"];
|
||||
}
|
||||
|
||||
}
|
@@ -41,3 +41,10 @@ services:
|
||||
Chill\MainBundle\Templating\ChillMarkdownRenderExtension:
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
Chill\MainBundle\Templating\Entity\AddressRender:
|
||||
arguments:
|
||||
- '@Symfony\Component\Templating\EngineInterface'
|
||||
tags:
|
||||
- { name: 'chill.render_entity' }
|
||||
|
||||
|
Reference in New Issue
Block a user