mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 06:14:59 +00:00
Fix some tests
This commit is contained in:
@@ -13,15 +13,22 @@ namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Form\ScopeType;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Class ScopeController.
|
||||
*/
|
||||
class ScopeController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Creates a new Scope entity.
|
||||
*
|
||||
@@ -52,17 +59,16 @@ class ScopeController extends AbstractController
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/admin/scope/{id}/edit", name="admin_scope_edit")
|
||||
*/
|
||||
public function editAction(mixed $id)
|
||||
public function editAction(Scope $scope, Request $request): Response
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$scope = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)->find($id);
|
||||
|
||||
if (!$scope) {
|
||||
throw $this->createNotFoundException('Unable to find Scope entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($scope);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('admin_scope_edit', ['id' => $scope->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/Scope/edit.html.twig', [
|
||||
'entity' => $scope,
|
||||
@@ -120,44 +126,12 @@ class ScopeController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits an existing Scope entity.
|
||||
*
|
||||
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/admin/scope/{id}/update", name="admin_scope_update", methods={"POST", "PUT"})
|
||||
*/
|
||||
public function updateAction(Request $request, mixed $id)
|
||||
{
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
$scope = $em->getRepository(\Chill\MainBundle\Entity\Scope::class)->find($id);
|
||||
|
||||
if (!$scope) {
|
||||
throw $this->createNotFoundException('Unable to find Scope entity.');
|
||||
}
|
||||
|
||||
$editForm = $this->createEditForm($scope);
|
||||
$editForm->handleRequest($request);
|
||||
|
||||
if ($editForm->isSubmitted() && $editForm->isValid()) {
|
||||
$em->flush();
|
||||
|
||||
return $this->redirectToRoute('admin_scope_edit', ['id' => $id]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/Scope/edit.html.twig', [
|
||||
'entity' => $scope,
|
||||
'edit_form' => $editForm->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to create a Scope entity.
|
||||
*
|
||||
* @param Scope $scope The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createCreateForm(Scope $scope)
|
||||
private function createCreateForm(Scope $scope): FormInterface
|
||||
{
|
||||
$form = $this->createForm(ScopeType::class, $scope, [
|
||||
'action' => $this->generateUrl('admin_scope_create'),
|
||||
@@ -173,15 +147,10 @@ class ScopeController extends AbstractController
|
||||
* Creates a form to edit a Scope entity.
|
||||
*
|
||||
* @param Scope $scope The entity
|
||||
*
|
||||
* @return \Symfony\Component\Form\Form The form
|
||||
*/
|
||||
private function createEditForm(Scope $scope)
|
||||
private function createEditForm(Scope $scope): FormInterface
|
||||
{
|
||||
$form = $this->createForm(ScopeType::class, $scope, [
|
||||
'action' => $this->generateUrl('admin_scope_update', ['id' => $scope->getId()]),
|
||||
'method' => 'PUT',
|
||||
]);
|
||||
$form = $this->createForm(ScopeType::class, $scope);
|
||||
|
||||
$form->add('submit', SubmitType::class, ['label' => 'Update']);
|
||||
|
||||
|
Reference in New Issue
Block a user