diff --git a/src/Controller/NpcController.php b/src/Controller/NpcController.php index d3725c5..58ce4e8 100644 --- a/src/Controller/NpcController.php +++ b/src/Controller/NpcController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Entity\Npc; +use App\Form\NpcGameNotesType; use App\Form\NpcType; use App\Repository\NpcRepository; use Doctrine\ORM\EntityManagerInterface; @@ -65,7 +66,32 @@ class NpcController extends AbstractController ]); } - #[Route('/npcs/{id}', name: 'app_npc_edit', requirements: ['id' => '\d+'], methods: ['GET', 'POST'])] + /** + * In-play detail page: everything read-only, plus the game-notes field. + */ + #[Route('/npcs/{id}', name: 'app_npc_show', requirements: ['id' => '\d+'], methods: ['GET', 'POST'])] + public function show(Request $request, Npc $npc, EntityManagerInterface $em): Response + { + $form = $this->createForm(NpcGameNotesType::class, $npc); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em->flush(); + $this->addFlash('success', 'Game notes saved.'); + + return $this->redirectToRoute('app_npc_show', ['id' => $npc->getId()]); + } + + return $this->render('npc/show.html.twig', [ + 'npc' => $npc, + 'form' => $form, + ]); + } + + /** + * Full edit of the NPC's structured fields (no game notes). + */ + #[Route('/npcs/{id}/edit', name: 'app_npc_edit', requirements: ['id' => '\d+'], methods: ['GET', 'POST'])] public function edit(Request $request, Npc $npc, EntityManagerInterface $em): Response { $form = $this->createForm(NpcType::class, $npc); @@ -75,7 +101,7 @@ class NpcController extends AbstractController $em->flush(); $this->addFlash('success', sprintf('Saved %s.', $npc->getName())); - return $this->redirectToRoute('app_npc_edit', ['id' => $npc->getId()]); + return $this->redirectToRoute('app_npc_show', ['id' => $npc->getId()]); } return $this->render('npc/edit.html.twig', [ diff --git a/src/Form/NpcGameNotesType.php b/src/Form/NpcGameNotesType.php new file mode 100644 index 0000000..bedfff4 --- /dev/null +++ b/src/Form/NpcGameNotesType.php @@ -0,0 +1,29 @@ +add('gameNotes', TextareaType::class, [ + 'required' => false, + 'label' => false, + 'attr' => ['rows' => 14, 'placeholder' => 'What happened with this NPC during play…'], + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults(['data_class' => Npc::class]); + } +} diff --git a/src/Form/NpcType.php b/src/Form/NpcType.php index ba0a908..5f769a1 100644 --- a/src/Form/NpcType.php +++ b/src/Form/NpcType.php @@ -51,12 +51,8 @@ class NpcType extends AbstractType ->add('mother', EntityType::class, $parent) ->add('villageStatus', EnumType::class, $enum(VillageStatus::class)) ->add('bloodCartInvolvement', EnumType::class, $enum(BloodCartInvolvement::class)) - ->add('mysteryImportance', EnumType::class, $enum(MysteryImportance::class)) - ->add('gameNotes', TextareaType::class, [ - 'required' => false, - 'label' => 'Game notes', - 'attr' => ['rows' => 10, 'placeholder' => 'What happened with this NPC during play…'], - ]); + ->add('mysteryImportance', EnumType::class, $enum(MysteryImportance::class)); + // gameNotes lives on the detail page, not this form. } public function configureOptions(OptionsResolver $resolver): void diff --git a/templates/npc/edit.html.twig b/templates/npc/edit.html.twig index b11d82d..f7260fd 100644 --- a/templates/npc/edit.html.twig +++ b/templates/npc/edit.html.twig @@ -1,6 +1,6 @@ {% extends 'base.html.twig' %} -{% block title %}{{ npc.name }} · NPC's · dmtools{% endblock %} +{% block title %}Edit {{ npc.name }} · NPC's · dmtools{% endblock %} {% block body %}