mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 17:39:06 +02:00
Added some basic part edit and create forms.
This commit is contained in:
parent
44c482caf2
commit
cc1badb853
15 changed files with 253 additions and 95 deletions
|
@ -33,9 +33,14 @@
|
|||
namespace App\Controller;
|
||||
|
||||
|
||||
use App\Entity\Category;
|
||||
use App\Entity\Part;
|
||||
use App\Form\PartType;
|
||||
use App\Services\AttachmentFilenameService;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class PartController extends AbstractController
|
||||
|
@ -58,4 +63,59 @@ class PartController extends AbstractController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/part/{id}/edit", name="part_edit", requirements={"id"="\d+"})
|
||||
*
|
||||
* @param Part $part
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function edit(Part $part, Request $request)
|
||||
{
|
||||
$form = $this->createForm(PartType::class, $part);
|
||||
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
|
||||
return $this->render('edit_part_info.html.twig',
|
||||
[
|
||||
"part" => $part,
|
||||
"form" => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/parts/new", name="part_new")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function new(Request $request, EntityManagerInterface $em)
|
||||
{
|
||||
$new_part = new Part();
|
||||
$category = $em->find(Category::class, 1);
|
||||
$new_part->setCategory($category);
|
||||
|
||||
$this->addFlash('success', 'Article Created!');
|
||||
|
||||
$form = $this->createForm(PartType::class, $new_part);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
/** @var Article $article */
|
||||
//$part = $form->getData();
|
||||
$em->persist($new_part);
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'Article Created! Knowledge is power!');
|
||||
return $this->redirectToRoute('part_edit',['id' => $new_part->getID()]);
|
||||
}
|
||||
|
||||
|
||||
return $this->render('edit_part_info.html.twig',
|
||||
[
|
||||
"part" => $new_part,
|
||||
"form" => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue