replace old method of getting translator with injection of translatorInterface

This commit is contained in:
2023-10-26 15:20:19 +02:00
parent cdfb084fe4
commit c6deb21606
7 changed files with 47 additions and 64 deletions

View File

@@ -113,7 +113,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
$em->remove($accompanyingCourse);
$em->flush();
$this->addFlash('success', $this->get('translator')
$this->addFlash('success', $this->translator
->trans('The accompanying course has been successfully removed.'));
if (null !== $person_id) {

View File

@@ -18,6 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class PersonAddressController
@@ -25,17 +26,11 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
*/
class PersonAddressController extends AbstractController
{
/**
* @var ValidatorInterface
*/
protected $validator;
/**
* PersonAddressController constructor.
*/
public function __construct(ValidatorInterface $validator)
public function __construct(private readonly ValidatorInterface $validator, private readonly TranslatorInterface $translator)
{
$this->validator = $validator;
}
/**
@@ -77,14 +72,14 @@ class PersonAddressController extends AbstractController
$this->addFlash(
'success',
$this->get('translator')->trans('The new address was created successfully')
$this->translator->trans('The new address was created successfully')
);
return $this->redirectToRoute('chill_person_address_list', [
'person_id' => $person->getId(),
]);
} else {
$this->addFlash('error', $this->get('translator')
$this->addFlash('error', $this->translator
->trans('Error! Address not created!'));
}
}
@@ -213,7 +208,7 @@ class PersonAddressController extends AbstractController
$this->getDoctrine()->getManager()
->flush();
$this->addFlash('success', $this->get('translator')->trans(
$this->addFlash('success', $this->translator->trans(
'The address has been successfully updated'
));
@@ -221,7 +216,7 @@ class PersonAddressController extends AbstractController
'person_id' => $person->getId(),
]);
} else {
$this->addFlash('error', $this->get('translator')
$this->addFlash('error', $this->translator
->trans('Error when updating the period'));
}
}