*/ final readonly class ClosingMotiveRender implements ChillEntityRenderInterface { use BoxUtilsChillEntityRenderTrait; private const SEPARATOR = ' > '; public function __construct( private TranslatableStringHelperInterface $translatableStringHelper, private TranslatorInterface $translator, ) {} public function renderBox($entity, array $options): string { return $this->getDefaultOpeningBox('closing-motive'). $this->renderString($entity, $options). $this->getDefaultClosingBox(); } public function renderString($entity, array $options): string { return $this->renderStringRecursive( $entity, '', $options ); } public function supports($entity, array $options): bool { return $entity instanceof ClosingMotive; } private function renderStringRecursive(ClosingMotive $motive, string $existing, array $options): string { $str = $this->translatableStringHelper->localize($motive->getName()); if ($motive->hasParent()) { if ('' !== $existing) { $str = $str.self::SEPARATOR.$existing; } $str = $this->renderStringRecursive( $motive->getParent(), $str, $options ); } if ('' !== $existing) { $str = $str.self::SEPARATOR.$existing; } if ($motive->isLeaf() && $motive->isCanceledAccompanyingPeriod()) { $str = $str.' '.$this->translator->trans('( Canceled period )'); } return $str; } }