Merge branch 'signature-app-master' into 'master'

Signature app master

Closes #307

See merge request Chill-Projet/chill-bundles!743
This commit is contained in:
2024-11-12 20:30:00 +00:00
426 changed files with 22236 additions and 2253 deletions

View File

@@ -56,9 +56,32 @@ class ChillTwigRoutingHelper extends AbstractExtension
new TwigFunction('chill_return_path_or', $this->getReturnPathOr(...), ['is_safe_callback' => $this->isUrlGenerationSafe(...)]),
new TwigFunction('chill_path_add_return_path', $this->getPathAddReturnPath(...), ['is_safe_callback' => $this->isUrlGenerationSafe(...)]),
new TwigFunction('chill_path_forward_return_path', $this->getPathForwardReturnPath(...), ['is_safe_callback' => $this->isUrlGenerationSafe(...)]),
new TwigFunction('chill_path_force_return_path', $this->getPathForceReturnPath(...), ['is_safe_callback' => $this->isUrlGenerationSafe(...)]),
];
}
/**
* Build a URL with a forced returnPath parameter.
*
* @param string $forcePath the forced path to return to
* @param string $name the name of the route
* @param array $parameters additional parameters for the URL
* @param bool $relative whether the URL should be relative
* @param string|null $label optional label for the return path
*
* @return string the generated URL
*/
public function getPathForceReturnPath(string $forcePath, string $name, array $parameters = [], $relative = false, $label = null): string
{
$params = [...$parameters, 'returnPath' => $forcePath];
if (null !== $label) {
$params['returnPathLabel'] = $label;
}
return $this->originalExtension->getPath($name, $params, $relative);
}
public function getLabelReturnPath($default)
{
$request = $this->requestStack->getCurrentRequest();

View File

@@ -19,24 +19,7 @@ use Twig\TwigFilter;
*/
class ChillEntityRenderExtension extends AbstractExtension
{
/**
* @var ChillEntityRender
*/
protected $defaultRender;
/**
* @var iterable|ChillEntityRenderInterface[]
*/
protected $renders = [];
/**
* ChillEntityRenderExtension constructor.
*/
public function __construct(iterable $renders)
{
$this->defaultRender = new ChillEntityRender();
$this->renders = $renders;
}
public function __construct(private readonly ChillEntityRenderManagerInterface $renderManager) {}
/**
* @return array|TwigFilter[]
@@ -53,34 +36,13 @@ class ChillEntityRenderExtension extends AbstractExtension
];
}
public function renderBox($entity, array $options = []): string
public function renderBox(?object $entity, array $options = []): string
{
if (null === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderBox($entity, $options);
return $this->renderManager->renderBox($entity, $options);
}
public function renderString($entity, array $options = []): string
public function renderString(?object $entity, array $options = []): string
{
if (null === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderString($entity, $options);
}
protected function getRender($entity, $options): ?ChillEntityRenderInterface
{
foreach ($this->renders as $render) {
if ($render->supports($entity, $options)) {
return $render;
}
}
return $this->defaultRender;
return $this->renderManager->renderString($entity, $options);
}
}

View File

@@ -15,7 +15,7 @@ namespace Chill\MainBundle\Templating\Entity;
* Interface to implement which will render an entity in template on a custom
* manner.
*
* @template T
* @template T of object
*/
interface ChillEntityRenderInterface
{
@@ -31,7 +31,7 @@ interface ChillEntityRenderInterface
* </span>
* ```
*
* @param T $entity
* @param T|null $entity
*
* @phpstan-pure
*/
@@ -42,7 +42,7 @@ interface ChillEntityRenderInterface
*
* Example: returning the name of a person.
*
* @param T $entity
* @param T|null $entity
*
* @phpstan-pure
*/

View File

@@ -0,0 +1,56 @@
<?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;
final readonly class ChillEntityRenderManager implements ChillEntityRenderManagerInterface
{
private ChillEntityRender $defaultRender;
public function __construct(/**
* @var iterable<ChillEntityRenderInterface>
*/
private iterable $renders,
) {
$this->defaultRender = new ChillEntityRender();
}
public function renderBox($entity, array $options = []): string
{
if (null === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderBox($entity, $options);
}
public function renderString($entity, array $options = []): string
{
if (null === $entity) {
return '';
}
return $this->getRender($entity, $options)
->renderString($entity, $options);
}
private function getRender($entity, $options): ChillEntityRenderInterface
{
foreach ($this->renders as $render) {
if ($render->supports($entity, $options)) {
return $render;
}
}
return $this->defaultRender;
}
}

View File

@@ -0,0 +1,19 @@
<?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;
interface ChillEntityRenderManagerInterface
{
public function renderBox(?object $entity, array $options = []): string;
public function renderString(?object $entity, array $options = []): string;
}

View File

@@ -0,0 +1,38 @@
<?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;
use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Twig\Environment;
final readonly class UserGroupRender implements UserGroupRenderInterface
{
public function __construct(private TranslatableStringHelperInterface $translatableStringHelper, private Environment $environment) {}
public function renderBox($entity, array $options): string
{
/* @var $entity UserGroup */
return $this->environment->render('@ChillMain/Entity/user_group.html.twig', ['user_group' => $entity]);
}
public function renderString($entity, array $options): string
{
/* @var $entity UserGroup */
return (string) $this->translatableStringHelper->localize($entity->getLabel());
}
public function supports(object $entity, array $options): bool
{
return $entity instanceof UserGroup;
}
}

View File

@@ -0,0 +1,14 @@
<?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;
interface UserGroupRenderInterface extends ChillEntityRenderInterface {}