' > ', ]; public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine) { $this->translatableStringHelper = $translatableStringHelper; $this->engine = $engine; } public function supports($entity, array $options): bool { return $entity instanceof SocialIssue; } /** * @param SocialIssue $socialIssue */ public function renderString($socialIssue, array $options): string { /** @var $socialIssue SocialIssue */ $options = array_merge(self::DEFAULT_ARGS, $options); $titles = [$this->translatableStringHelper->localize($socialIssue->getTitle())]; // loop to parent, until root while ($socialIssue->hasParent()) { $socialIssue = $socialIssue->getParent(); $titles[] = $this->translatableStringHelper->localize( $socialIssue->getTitle() ); } $titles = \array_reverse($titles); return \implode($options[self::SEPARATOR_KEY], $titles); } protected function buildParents(SocialIssue $socialIssue): array { $parents = []; while ($socialIssue->hasParent()) { $socialIssue = $parents[] = $socialIssue->getParent(); } return $parents; } /** * * @param SocialIssue $socialIssue */ public function renderBox($socialIssue, array $options): string { $options = array_merge(self::DEFAULT_ARGS, $options); // give some help to twig: an array of parents $parents = $this->buildParents($socialIssue); return $this ->engine ->render( '@ChillPerson/Entity/social_issue.html.twig', [ 'socialIssue' => $socialIssue, 'parents' => $parents, 'options' => $options ] ); } }