review: fix stuffs on socialAction and socialIssue filters:

* filters call static entity method
* add renderString option to manage add_children
* add tests on new entity method getDescendantsWithThisFor..()
* rename function in repository
* rename 'Select2..' classes by 'Pick..' and replace all occurences
This commit is contained in:
2022-10-17 09:52:29 +02:00
parent 71f989f00e
commit 32ddc5465c
22 changed files with 244 additions and 151 deletions

View File

@@ -15,7 +15,7 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_reverse;
use function implode;
@@ -23,18 +23,34 @@ final class SocialIssueRender implements ChillEntityRenderInterface
{
public const DEFAULT_ARGS = [
self::SEPARATOR_KEY => ' > ',
self::SHOW_AND_CHILDREN => false,
self::AND_CHILDREN_MENTION => 'social_issue.and children',
];
public const SEPARATOR_KEY = 'default.separator';
/**
* Show a mention "and children" on each SocialIssue, if the social issue
* has at least one child
*/
public const SHOW_AND_CHILDREN = 'show_and_children';
public const AND_CHILDREN_MENTION = 'show_and_children_mention';
private EngineInterface $engine;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
{
private TranslatorInterface $translator;
public function __construct(
TranslatableStringHelper $translatableStringHelper,
EngineInterface $engine,
TranslatorInterface $translator
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->engine = $engine;
$this->translator = $translator;
}
/**
@@ -78,7 +94,13 @@ final class SocialIssueRender implements ChillEntityRenderInterface
$titles = array_reverse($titles);
return implode($options[self::SEPARATOR_KEY], $titles);
$title = implode($options[self::SEPARATOR_KEY], $titles);
if ($options[self::SHOW_AND_CHILDREN] && $socialIssue->hasChildren()) {
$title .= ' (' . $this->translator->trans($options[self::AND_CHILDREN_MENTION]) . ')';
}
return $title;
}
public function supports($entity, array $options): bool