diff --git a/src/Controller/Config/MaterialTypeController.php b/src/Controller/Config/MaterialTypeController.php new file mode 100644 index 0000000..e6b6e51 --- /dev/null +++ b/src/Controller/Config/MaterialTypeController.php @@ -0,0 +1,89 @@ +entityManager = $entityManager; + $this->materialTypeRepository = $materialTypeRepository; + } + + /** + * List of material types + * + * @return Response The response + */ + #[Route('/', name: 'config_materialType_list', alias: 'config_materialType')] + public function list (): Response { + return $this->render( + 'Config/MaterialType/List.html.twig', + [ + 'materialTypes' => $this->materialTypeRepository->findAll(), + ] + ); + } + + /** + * Edit/Create a material type + * + * @return Response The response + */ + #[Route('/Create', name: 'config_materialType_create')] + #[Route('/Edit-{id}', name: 'config_materialType_edit')] + public function edit (Request $request, ?MaterialType $materialType = null): Response { + $materialType ??= new MaterialType(); + + $form = $this->createForm(MaterialTypeEditForm::class, $materialType); + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->persist($materialType); + $this->entityManager->flush(); + + $this->addFlash(FlashType::SUCCESS, 'Le type de matériau a bien été enregistré.'); + return $this->redirectToRoute('config_materialType_list'); + } + + return $this->render('Config/MaterialType/Edit.html.twig', [ + 'form' => $form->createView(), + ]); + } + + /** + * Delete a material type + * + * @return Response The response + */ + #[Route('/Delete-{id}', name: 'config_materialType_delete')] + public function delete (MaterialType $materialType): Response { + $this->entityManager->remove($materialType); + $this->entityManager->flush(); + + $this->addFlash(FlashType::SUCCESS, 'Le type de matériau a bien été supprimé.'); + return $this->redirectToRoute('config_materialType_list'); + } +} diff --git a/src/Form/Config/MaterialTypeEditForm.php b/src/Form/Config/MaterialTypeEditForm.php new file mode 100644 index 0000000..020bee4 --- /dev/null +++ b/src/Form/Config/MaterialTypeEditForm.php @@ -0,0 +1,45 @@ +setDefaults( + [ + 'data_class' => MaterialType::class, + ] + ); + } + + /** + * @inheritDoc + */ + public function buildForm (FormBuilderInterface $builder, array $options): void { + $builder + ->add('name', null, [ + 'label' => 'Nom', + ]) + ->add('stackName', null, [ + 'label' => 'Nom de la pile', + ]) + ->add('stackSize', null, [ + 'label' => 'Taille de la pile', + ]) + ->add('submit', SubmitType::class, [ + 'label' => 'Enregistrer', + ]); + } +} \ No newline at end of file diff --git a/templates/Config/MaterialType/Edit.html.twig b/templates/Config/MaterialType/Edit.html.twig new file mode 100644 index 0000000..765bc3e --- /dev/null +++ b/templates/Config/MaterialType/Edit.html.twig @@ -0,0 +1,8 @@ +{% extends 'base.html.twig' %} + +{% block title %}Modification type de matériau - {{ parent() }}{% endblock %} + +{% block mainContent %} +
Bienvenu sur Recipe Manager, le gestionnaire de recette de jeux vidéos.
Merci de vous connecter ou créer un compte pour commencer.