fix misc in activity (WIP)

This commit is contained in:
2021-06-08 16:55:29 +02:00
parent a947634f30
commit 0aa909f060
14 changed files with 225 additions and 55 deletions

View File

@@ -0,0 +1,71 @@
<?php
namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface;
class SocialActionRender implements ChillEntityRenderInterface
{
private TranslatableStringHelper $translatableStringHelper;
private EngineInterface $engine;
public const SEPARATOR_KEY = 'default.separator';
public const DEFAULT_ARGS = [
self::SEPARATOR_KEY => ' > ',
];
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
{
$this->translatableStringHelper = $translatableStringHelper;
$this->engine = $engine;
}
public function supports($entity, array $options): bool
{
return $entity instanceof SocialAction;
}
public function renderString($socialAction, array $options): string
{
/** @var $socialAction SocialAction */
$options = \array_merge(self::DEFAULT_ARGS, $options);
$str = $this->translatableStringHelper->localize($socialAction->getTitle());
while ($socialAction->hasParent()) {
$socialAction = $socialAction->getParent();
$str .= $options[self::SEPARATOR_KEY].$this->translatableStringHelper->localize(
$socialAction->getTitle()
);
}
return $str;
}
protected function buildParents($socialAction): array
{
$parents = [];
while ($socialAction->hasParent()) {
$socialAction = $parents[] = $socialAction->getParent();
}
return $parents;
}
public function renderBox($socialAction, array $options): string
{
$options = \array_merge(self::DEFAULT_ARGS, $options);
// give some help to twig: an array of parents
$parents = $this->buildParents($socialAction);
return $this->engine->render('@ChillPerson/Entity/social_action.html.twig', [
'socialAction' => $socialAction,
'parents' => $parents,
'options' => $options
]);
}
}