mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 11:33:49 +00:00
first impl
This commit is contained in:
@@ -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
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user