Skip to content

Commit 56e964a

Browse files
keichingerGuikingone
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 57bffdc commit 56e964a

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
@@ -687,15 +687,8 @@ the relationship between the removed ``Tag`` and ``Task`` object.
687687
use Doctrine\Common\Collections\ArrayCollection;
688688

689689
// ...
690-
public function edit($id, Request $request)
690+
public function edit(Task $task, Request $request, EntityManagerInterface $entityManager)
691691
{
692-
$entityManager = $this->getDoctrine()->getManager();
693-
$task = $entityManager->getRepository(Task::class)->find($id);
694-
695-
if (!$task) {
696-
throw $this->createNotFoundException('No task found for id '.$id);
697-
}
698-
699692
$originalTags = new ArrayCollection();
700693

701694
// Create an ArrayCollection of the current Tag objects in the database
@@ -707,7 +700,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
707700

708701
$editForm->handleRequest($request);
709702

710-
if ($editForm->isValid()) {
703+
if ($editForm->isSubmitted() && $editForm->isValid()) {
711704

712705
// remove the relationship between the tag and the Task
713706
foreach ($originalTags as $tag) {

0 commit comments

Comments
 (0)