*/ class ClosingMotiveRender implements ChillEntityRenderInterface { use BoxUtilsChillEntityRenderTrait; private const SEPARATOR = ' > '; public function __construct(private readonly TranslatableStringHelper $translatableStringHelper) {} 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, '', //$this->translatableStringHelper->localize($entity->getName()), $options ); } public function supports($entity, array $options): bool { return $entity instanceof ClosingMotive; } private function renderStringRecursive(ClosingMotive $motive, string $existing, array $options) { $newExisting = $this->translatableStringHelper->localize($motive->getName()); $isCancled = $motive->getIsCanceledAccompanyingPeriod() ? $this->translator->trans('( Canceled period )') : ''; if ($motive->hasParent()) { if ('' !== $existing) { $newExisting = $newExisting . self::SEPARATOR . $existing; } return $this->renderStringRecursive( $motive->getParent(), $newExisting . ' ' . $isCancled, $options ); } if ('' !== $existing) { return $newExisting . self::SEPARATOR . $existing; } return $newExisting . ' ' . $isCancled; } }