From 6bba6f68b34b166b6498d4d7407adc29bcf3fd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 13 Jan 2023 16:15:58 +0100 Subject: [PATCH] DX: Remove deprecation on `$this->get` inside controller --- .../Controller/CalendarController.php | 17 +++++++++++------ .../Entity/SocialWork/SocialIssue.php | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index db5f2ec16..550c6e984 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -45,6 +45,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Contracts\Translation\TranslatorInterface; class CalendarController extends AbstractController { @@ -68,6 +69,8 @@ class CalendarController extends AbstractController private TranslatableStringHelperInterface $translatableStringHelper; + private TranslatorInterface $translator; + private UserRepositoryInterface $userRepository; public function __construct( @@ -81,7 +84,8 @@ class CalendarController extends AbstractController TranslatableStringHelperInterface $translatableStringHelper, PersonRepository $personRepository, AccompanyingPeriodRepository $accompanyingPeriodRepository, - UserRepositoryInterface $userRepository + UserRepositoryInterface $userRepository, + TranslatorInterface $translator ) { $this->calendarACLAwareRepository = $calendarACLAwareRepository; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; @@ -94,6 +98,7 @@ class CalendarController extends AbstractController $this->personRepository = $personRepository; $this->accompanyingPeriodRepository = $accompanyingPeriodRepository; $this->userRepository = $userRepository; + $this->translator = $translator; } /** @@ -131,7 +136,7 @@ class CalendarController extends AbstractController $em->remove($entity); $em->flush(); - $this->addFlash('success', $this->get('translator') + $this->addFlash('success', $this->translator ->trans('The calendar item has been successfully removed.')); return new RedirectResponse($redirectRoute); @@ -190,7 +195,7 @@ class CalendarController extends AbstractController if ($form->isSubmitted() && $form->isValid()) { $em->flush(); - $this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!')); + $this->addFlash('success', $this->translator->trans('Success : calendar item updated!')); if ($form->get('save_and_upload_doc')->isClicked()) { return $this->redirectToRoute('chill_calendar_calendardoc_new', ['id' => $entity->getId()]); @@ -210,7 +215,7 @@ class CalendarController extends AbstractController } if ($form->isSubmitted() && !$form->isValid()) { - $this->addFlash('error', $this->get('translator')->trans('This form contains errors')); + $this->addFlash('error', $this->translator->trans('This form contains errors')); } $entity_array = $this->serializer->normalize($entity, 'json', ['groups' => 'read']); @@ -369,7 +374,7 @@ class CalendarController extends AbstractController $em->persist($entity); $em->flush(); - $this->addFlash('success', $this->get('translator')->trans('Success : calendar item created!')); + $this->addFlash('success', $this->translator->trans('Success : calendar item created!')); if ($form->get('save_and_upload_doc')->isClicked()) { return $this->redirectToRoute('chill_calendar_calendardoc_new', ['id' => $entity->getId()]); @@ -393,7 +398,7 @@ class CalendarController extends AbstractController } if ($form->isSubmitted() && !$form->isValid()) { - $this->addFlash('error', $this->get('translator')->trans('This form contains errors')); + $this->addFlash('error', $this->translator->trans('This form contains errors')); } if (null === $view) { diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index 42c8442c1..675a1a923 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -356,7 +356,9 @@ class SocialIssue { $this->parent = $parent; - $parent->addChild($this); + if (null !== $parent) { + $parent->addChild($this); + } return $this; }