mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 13:33:48 +00:00
Merge remote-tracking branch 'origin/master' into track-address-reference-update
This commit is contained in:
@@ -90,7 +90,7 @@ class ChillTwigHelper extends AbstractExtension
|
||||
|
||||
return $twig->render($t, array_merge([
|
||||
'value' => $value,
|
||||
'message' => $message ?? 'No value',
|
||||
'message' => $message,
|
||||
], $options));
|
||||
}
|
||||
}
|
||||
|
@@ -11,15 +11,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
/**
|
||||
* @deprecated load @link{BoxUtilsChillEntityRenderTrait} in the render
|
||||
*/
|
||||
abstract class AbstractChillEntityRender implements ChillEntityRenderInterface
|
||||
{
|
||||
protected function getDefaultClosingBox(): string
|
||||
{
|
||||
return '</section>';
|
||||
}
|
||||
|
||||
protected function getDefaultOpeningBox($classSuffix): string
|
||||
{
|
||||
return '<section class="chill-entity entity-' . $classSuffix . '">';
|
||||
}
|
||||
use BoxUtilsChillEntityRenderTrait;
|
||||
}
|
||||
|
@@ -20,6 +20,9 @@ use Symfony\Component\Templating\EngineInterface;
|
||||
use function array_merge;
|
||||
use function strtr;
|
||||
|
||||
/**
|
||||
* @implements ChillEntityRenderInterface<Address>
|
||||
*/
|
||||
class AddressRender implements ChillEntityRenderInterface
|
||||
{
|
||||
public const DEFAULT_OPTIONS = [
|
||||
@@ -39,16 +42,12 @@ class AddressRender implements ChillEntityRenderInterface
|
||||
|
||||
public function __construct(
|
||||
EngineInterface $templating,
|
||||
TranslatableStringHelperInterface $translatableStringHelper)
|
||||
{
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->templating = $templating;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address addr
|
||||
* @param mixed $addr
|
||||
*/
|
||||
public function renderBox($addr, array $options): string
|
||||
{
|
||||
$options = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
@@ -70,8 +69,8 @@ class AddressRender implements ChillEntityRenderInterface
|
||||
{
|
||||
$lines = [];
|
||||
|
||||
if (null !== $addr->getPostCode()) {
|
||||
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
|
||||
if (null !== $addr->getPostcode()) {
|
||||
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
|
||||
$lines[] = $this->renderIntraBuildingLine($addr);
|
||||
$lines[] = $this->renderBuildingLine($addr);
|
||||
$lines[] = $this->renderStreetLine($addr);
|
||||
@@ -118,10 +117,8 @@ class AddressRender implements ChillEntityRenderInterface
|
||||
|
||||
$res = trim($street . ', ' . $streetNumber, ', ');
|
||||
|
||||
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
|
||||
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
|
||||
$res = trim($streetNumber . ', ' . $street, ', ');
|
||||
}
|
||||
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
|
||||
$res = trim($streetNumber . ', ' . $street, ', ');
|
||||
}
|
||||
|
||||
if ((',' === $res) || ('' === $res)) {
|
||||
@@ -131,10 +128,6 @@ class AddressRender implements ChillEntityRenderInterface
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address addr
|
||||
* @param mixed $addr
|
||||
*/
|
||||
public function renderString($addr, array $options): string
|
||||
{
|
||||
return implode(' — ', $this->renderLines($addr));
|
||||
@@ -164,10 +157,8 @@ class AddressRender implements ChillEntityRenderInterface
|
||||
$res = null;
|
||||
}
|
||||
|
||||
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
|
||||
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
|
||||
$res = $addr->getBuildingName();
|
||||
}
|
||||
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
|
||||
$res = $addr->getBuildingName();
|
||||
}
|
||||
|
||||
return $res;
|
||||
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
trait BoxUtilsChillEntityRenderTrait
|
||||
{
|
||||
protected function getDefaultClosingBox(): string
|
||||
{
|
||||
return '</section>';
|
||||
}
|
||||
|
||||
protected function getDefaultOpeningBox($classSuffix): string
|
||||
{
|
||||
return '<section class="chill-entity entity-' . $classSuffix . '">';
|
||||
}
|
||||
}
|
@@ -14,8 +14,10 @@ namespace Chill\MainBundle\Templating\Entity;
|
||||
/**
|
||||
* Render an entity using `__toString()`.
|
||||
*/
|
||||
class ChillEntityRender extends AbstractChillEntityRender
|
||||
class ChillEntityRender implements ChillEntityRenderInterface
|
||||
{
|
||||
use BoxUtilsChillEntityRenderTrait;
|
||||
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
return $this->getDefaultOpeningBox('default') . $entity
|
||||
|
@@ -14,6 +14,8 @@ namespace Chill\MainBundle\Templating\Entity;
|
||||
/**
|
||||
* Interface to implement which will render an entity in template on a custom
|
||||
* manner.
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
interface ChillEntityRenderInterface
|
||||
{
|
||||
@@ -29,7 +31,7 @@ interface ChillEntityRenderInterface
|
||||
* </span>
|
||||
* ```
|
||||
*
|
||||
* @param type $entity
|
||||
* @param T $entity
|
||||
*/
|
||||
public function renderBox($entity, array $options): string;
|
||||
|
||||
@@ -38,14 +40,12 @@ interface ChillEntityRenderInterface
|
||||
*
|
||||
* Example: returning the name of a person.
|
||||
*
|
||||
* @param object $entity
|
||||
* @param T $entity
|
||||
*/
|
||||
public function renderString($entity, array $options): string;
|
||||
|
||||
/**
|
||||
* Return true if the class support this object for the given options.
|
||||
*
|
||||
* @param type $entity
|
||||
*/
|
||||
public function supports($entity, array $options): bool;
|
||||
public function supports(object $entity, array $options): bool;
|
||||
}
|
||||
|
@@ -13,33 +13,32 @@ namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\MainBundle\Repository\UserRepositoryInterface;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
use function array_merge;
|
||||
|
||||
class CommentRender extends AbstractChillEntityRender
|
||||
/**
|
||||
* @implements ChillEntityRenderInterface<CommentEmbeddable>
|
||||
*/
|
||||
class CommentRender implements ChillEntityRenderInterface
|
||||
{
|
||||
use BoxUtilsChillEntityRenderTrait;
|
||||
/**
|
||||
* @var EngineInterface
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
/**
|
||||
* @var \Chill\MainBundle\Repository\UserRepository
|
||||
*/
|
||||
private $userRepository;
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
public function __construct(
|
||||
UserRepository $userRepository,
|
||||
UserRepositoryInterface $userRepository,
|
||||
EngineInterface $engine
|
||||
) {
|
||||
$this->userRepository = $userRepository;
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommentEmbeddable $entity
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
// default options
|
||||
@@ -50,7 +49,7 @@ class CommentRender extends AbstractChillEntityRender
|
||||
'metadata' => true,
|
||||
], $options);
|
||||
|
||||
if ($entity->getUserId()) {
|
||||
if (null !== $entity->getUserId()) {
|
||||
$user = $this->userRepository->find($entity->getUserId());
|
||||
}
|
||||
|
||||
@@ -67,9 +66,6 @@ class CommentRender extends AbstractChillEntityRender
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommentEmbeddable $entity
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
return $entity->getComment();
|
||||
|
@@ -19,6 +19,9 @@ use Symfony\Component\Templating\EngineInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function array_merge;
|
||||
|
||||
/**
|
||||
* @implements ChillEntityRenderInterface<User>
|
||||
*/
|
||||
class UserRender implements ChillEntityRenderInterface
|
||||
{
|
||||
public const DEFAULT_OPTIONS = [
|
||||
@@ -50,9 +53,6 @@ class UserRender implements ChillEntityRenderInterface
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $entity
|
||||
*/
|
||||
public function renderString($entity, array $options): string
|
||||
{
|
||||
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
@@ -70,23 +70,23 @@ class DelegatedBlockRenderingEvent extends Event implements ArrayAccess
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function offsetExists($offset)
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return isset($this->context[$offset]);
|
||||
}
|
||||
|
||||
public function offsetGet($offset)
|
||||
public function offsetGet($offset): mixed
|
||||
{
|
||||
return $this->context[$offset];
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value)
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
throw new RuntimeException('The event context is read-only, you are not '
|
||||
. 'allowed to update it.');
|
||||
}
|
||||
|
||||
public function offsetUnset($offset)
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
throw new RuntimeException('The event context is read-only, you are not '
|
||||
. 'allowed to update it.');
|
||||
|
Reference in New Issue
Block a user