mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-07 19:49:30 +00:00
Dont call translator inside the form classes.
Translation is already done in the templates, so translator calls in form classes, are bad for performance and readability.
This commit is contained in:
parent
e7b920c4fe
commit
89acfff857
28 changed files with 1875 additions and 2259 deletions
|
|
@ -107,13 +107,13 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
$this->addFlash('success', $this->translator->trans('entity.edit_flash'));
|
||||
$this->addFlash('success', 'entity.edit_flash');
|
||||
|
||||
//Rebuild form, so it is based on the updated data. Important for the parent field!
|
||||
//We can not use dynamic form events here, because the parent entity list is build from database!
|
||||
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
|
||||
} elseif ($form->isSubmitted() && !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans('entity.edit_flash.invalid'));
|
||||
$this->addFlash('error', 'entity.edit_flash.invalid');
|
||||
}
|
||||
|
||||
return $this->render($this->twig_template, [
|
||||
|
|
@ -163,13 +163,13 @@ abstract class BaseAdminController extends AbstractController
|
|||
|
||||
$em->persist($new_entity);
|
||||
$em->flush();
|
||||
$this->addFlash('success', $this->translator->trans('entity.created_flash'));
|
||||
$this->addFlash('success', 'entity.created_flash');
|
||||
|
||||
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $new_entity->getID()]);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans('entity.created_flash.invalid'));
|
||||
$this->addFlash('error', 'entity.created_flash.invalid');
|
||||
}
|
||||
|
||||
//Import form
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Class DebugController.
|
||||
*/
|
||||
class DebugController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/debug/flash_test")
|
||||
*/
|
||||
public function flashTest()
|
||||
{
|
||||
$this->addFlash('success', 'Success Flash Message!');
|
||||
$this->addFlash('error', 'Error Flash Message!');
|
||||
$this->addFlash('warning', 'Warning Flash Message!');
|
||||
$this->addFlash('notice', 'Notice Flash Message!');
|
||||
$this->addFlash('info', 'Info Flash Message! <b>Test</b>');
|
||||
|
||||
$this->addFlash('testkjfd', 'Blabla. This message type should be not know to template!');
|
||||
|
||||
return $this->render('base.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/debug/dummy")
|
||||
*/
|
||||
public function dummy(TranslatorInterface $translator)
|
||||
{
|
||||
//Here we collect translation keys automatically created, so they can be extracted easily
|
||||
|
||||
//Validators:
|
||||
$translator->trans('validator.noneofitschild.self');
|
||||
$translator->trans('validator.noneofitschild.children');
|
||||
$translator->trans('validator.isSelectable');
|
||||
$translator->trans('validator.part_lot.location_full.no_increasment');
|
||||
$translator->trans('validator.part_lot.location_full');
|
||||
$translator->trans('validator.part_lot.only_existing');
|
||||
$translator->trans('validator.part_lot.single_part');
|
||||
|
||||
//Manufacturer status
|
||||
$translator->trans('m_status.active.help');
|
||||
$translator->trans('m_status.announced.help');
|
||||
$translator->trans('m_status.discontinued.help');
|
||||
$translator->trans('m_status.eol.help');
|
||||
$translator->trans('m_status.nrfnd.help');
|
||||
$translator->trans('m_status.unknown.help');
|
||||
|
||||
//Flash titles
|
||||
$translator->trans('flash.success');
|
||||
$translator->trans('flash.error');
|
||||
$translator->trans('flash.warning');
|
||||
$translator->trans('flash.notice');
|
||||
$translator->trans('flash.info');
|
||||
|
||||
$translator->trans('validator.noLockout');
|
||||
}
|
||||
}
|
||||
|
|
@ -97,11 +97,11 @@ class PartController extends AbstractController
|
|||
|
||||
$em->persist($part);
|
||||
$em->flush();
|
||||
$this->addFlash('info', $translator->trans('part.edited_flash'));
|
||||
$this->addFlash('info', 'part.edited_flash');
|
||||
//Reload form, so the SIUnitType entries use the new part unit
|
||||
$form = $this->createForm(PartBaseType::class, $part);
|
||||
} elseif ($form->isSubmitted() && !$form->isValid()) {
|
||||
$this->addFlash('error', $translator->trans('part.edited_flash.invalid'));
|
||||
$this->addFlash('error', 'part.edited_flash.invalid');
|
||||
}
|
||||
|
||||
return $this->render('Parts/edit/edit_part_info.html.twig',
|
||||
|
|
@ -180,13 +180,13 @@ class PartController extends AbstractController
|
|||
|
||||
$em->persist($new_part);
|
||||
$em->flush();
|
||||
$this->addFlash('success', $translator->trans('part.created_flash'));
|
||||
$this->addFlash('success', 'part.created_flash');
|
||||
|
||||
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && !$form->isValid()) {
|
||||
$this->addFlash('error', $translator->trans('part.created_flash.invalid'));
|
||||
$this->addFlash('error', 'part.created_flash.invalid');
|
||||
}
|
||||
|
||||
return $this->render('Parts/edit/new_part.html.twig',
|
||||
|
|
@ -216,7 +216,7 @@ class PartController extends AbstractController
|
|||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em->persist($new_part);
|
||||
$em->flush();
|
||||
$this->addFlash('success', $translator->trans('part.created_flash'));
|
||||
$this->addFlash('success', 'part.created_flash');
|
||||
|
||||
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class SecurityController extends AbstractController
|
|||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$passwordReset->request($form->getData()['user']);
|
||||
$this->addFlash('success', $this->translator->trans('pw_reset.request.success'));
|
||||
$this->addFlash('success', 'pw_reset.request.success');
|
||||
return $this->redirectToRoute('login');
|
||||
}
|
||||
|
||||
|
|
@ -152,9 +152,9 @@ class SecurityController extends AbstractController
|
|||
//Try to set the new password
|
||||
$success = $passwordReset->setNewPassword($data['username'], $data['token'], $data['new_password']);
|
||||
if (!$success) {
|
||||
$this->addFlash('error', $this->translator->trans('pw_reset.new_pw.error'));
|
||||
$this->addFlash('error', 'pw_reset.new_pw.error');
|
||||
} else {
|
||||
$this->addFlash('success', $this->translator->trans('pw_reset.new_pw.success'));
|
||||
$this->addFlash('success', 'pw_reset.new_pw.success');
|
||||
return $this->redirectToRoute('login');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue