true, 'user_job' => true, 'absence' => true, ]; private EngineInterface $engine; private TranslatableStringHelper $translatableStringHelper; private TranslatorInterface $translator; public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine, TranslatorInterface $translator) { $this->translatableStringHelper = $translatableStringHelper; $this->engine = $engine; $this->translator = $translator; } public function renderBox($entity, array $options): string { $opts = array_merge(self::DEFAULT_OPTIONS, $options); return $this->engine->render('@ChillMain/Entity/user.html.twig', [ 'user' => $entity, 'opts' => $opts, ]); } /** * @param User $entity */ public function renderString($entity, array $options): string { $opts = array_merge(self::DEFAULT_OPTIONS, $options); $str = $entity->getLabel(); if (null !== $entity->getUserJob() && $opts['user_job']) { $str .= ' (' . $this->translatableStringHelper ->localize($entity->getUserJob()->getLabel()) . ')'; } if (null !== $entity->getMainScope() && $opts['main_scope']) { $str .= ' (' . $this->translatableStringHelper ->localize($entity->getMainScope()->getName()) . ')'; } if ($entity->isAbsent() && $opts['absence']) { $str .= ' (' . $this->translator->trans('absence.Absent') . ')'; } return $str; } public function supports($entity, array $options): bool { return $entity instanceof User; } }