Skip to content

Commit 6f2c417

Browse files
keichingerjaviereguiluz
authored andcommitted
Add necessary call to Form::isSubmitted and remove boilerplate
- Since Symfony 4.0 it's required to call `Form::isSubmitted()` before you call `Form::isValid()` - Remove some unnecessary boilerplate code by using automatic parameter conversion and parameter injection of the `EntityManager`
1 parent d5f87ad commit 6f2c417

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

form/form_collections.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,8 @@ the relationship between the removed ``Tag`` and ``Task`` object.
655655
use Doctrine\Common\Collections\ArrayCollection;
656656

657657
// ...
658-
public function edit($id, Request $request)
658+
public function edit(Task $task, Request $request, EntityManagerInterface $entityManager)
659659
{
660-
$entityManager = $this->getDoctrine()->getManager();
661-
$task = $entityManager->getRepository(Task::class)->find($id);
662-
663-
if (!$task) {
664-
throw $this->createNotFoundException('No task found for id '.$id);
665-
}
666-
667660
$originalTags = new ArrayCollection();
668661

669662
// Create an ArrayCollection of the current Tag objects in the database
@@ -675,7 +668,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
675668

676669
$editForm->handleRequest($request);
677670

678-
if ($editForm->isValid()) {
671+
if ($editForm->isSubmitted() && $editForm->isValid()) {
679672

680673
// remove the relationship between the tag and the Task
681674
foreach ($originalTags as $tag) {

0 commit comments

Comments
 (0)