From fbbf421d8b2b92ce308df1a8bf56f0208b179273 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 8 Jan 2024 12:35:09 +0100 Subject: [PATCH] Handle DateTime type for activity while DateTimeImmutable is expected --- src/Bundle/ChillMainBundle/Entity/User.php | 4 ++-- .../Templating/Entity/UserRender.php | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index c95ccbf33..8b0412a38 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -274,7 +274,7 @@ class User implements UserInterface, \Stringable return $this->mainLocation; } - public function getMainScope(\DateTime $atDate = null): ?Scope + public function getMainScope(\DateTimeImmutable $atDate = null): ?Scope { $atDate ??= new \DateTimeImmutable('now'); @@ -326,7 +326,7 @@ class User implements UserInterface, \Stringable return $this->salt; } - public function getUserJob(\DateTime $atDate = null): ?UserJob + public function getUserJob(\DateTimeImmutable $atDate = null): ?UserJob { $atDate ??= new \DateTimeImmutable('now'); diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php index 376b3b454..a03acb476 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php @@ -13,6 +13,7 @@ namespace Chill\MainBundle\Templating\Entity; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Monolog\DateTimeImmutable; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -35,6 +36,8 @@ class UserRender implements ChillEntityRenderInterface { $opts = \array_merge(self::DEFAULT_OPTIONS, $options); + $opts['at_date'] = $opts['at_date'] instanceOf \DateTime ? DateTimeImmutable::createFromMutable($opts['at_date']) : $opts['at_date']; + return $this->engine->render('@ChillMain/Entity/user.html.twig', [ 'user' => $entity, 'opts' => $opts, @@ -45,16 +48,18 @@ class UserRender implements ChillEntityRenderInterface { $opts = \array_merge(self::DEFAULT_OPTIONS, $options); + $immutableAtDate = $opts['at_date'] instanceOf \DateTime ? DateTimeImmutable::createFromMutable($opts['at_date']) : $opts['at_date']; + $str = $entity->getLabel(); - if (null !== $entity->getUserJob($opts['at_date']) && $opts['user_job']) { + if (null !== $entity->getUserJob($immutableAtDate) && $opts['user_job']) { $str .= ' ('.$this->translatableStringHelper - ->localize($entity->getUserJob($opts['at_date'])->getLabel()).')'; + ->localize($entity->getUserJob($immutableAtDate)->getLabel()).')'; } - if (null !== $entity->getMainScope($opts['at_date']) && $opts['main_scope']) { + if (null !== $entity->getMainScope($immutableAtDate) && $opts['main_scope']) { $str .= ' ('.$this->translatableStringHelper - ->localize($entity->getMainScope($opts['at_date'])->getName()).')'; + ->localize($entity->getMainScope($immutableAtDate)->getName()).')'; } if ($entity->isAbsent() && $opts['absence']) {