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

@@ -18,12 +18,15 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class CustomFieldController.
*/
class CustomFieldController extends AbstractController
{
public function __construct(private readonly TranslatorInterface $translator){}
/**
* Creates a new CustomField entity.
*
@@ -40,13 +43,13 @@ class CustomFieldController extends AbstractController
$em->persist($entity);
$em->flush();
$this->addFlash('success', $this->get('translator')
$this->addFlash('success', $this->translator
->trans('The custom field has been created'));
return $this->redirectToRoute('customfieldsgroup_show', ['id' => $entity->getCustomFieldsGroup()->getId()]);
}
$this->addFlash('error', $this->get('translator')
$this->addFlash('error', $this->translator
->trans('The custom field form contains errors'));
return $this->render('@ChillCustomFields/CustomField/new.html.twig', [
@@ -130,13 +133,13 @@ class CustomFieldController extends AbstractController
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em->flush();
$this->addFlash('success', $this->get('translator')
$this->addFlash('success', $this->translator
->trans('The custom field has been updated'));
return $this->redirectToRoute('customfield_edit', ['id' => $id]);
}
$this->addFlash('error', $this->get('translator')
$this->addFlash('error', $this->translator
->trans('The custom field form contains errors'));
return $this->render('@ChillCustomFields/CustomField/edit.html.twig', [