Skip to content

Commit a2864b3

Browse files
committed
minor symfony#10068 Add necessary call to Form::isSubmitted and remove boilerplate (keichinger, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 4.0 branch instead (closes symfony#10068). Discussion ---------- Add necessary call to Form::isSubmitted and remove boilerplate This code example was the last parts of the docs that wasn't calling `Form::isSubmitted()` as required as of Symfony 4.0. Other than that I've simplified the action a little bit to remove some rather unnecessary noise in an already little more complicated example to ease reading and understanding it. If you want to keep the boilerplate, I'm more than happy to remove it from this PR :) Commits ------- ae265d7 Update form_collections.rst f140342 Minor refactor 6f2c417 Add necessary call to Form::isSubmitted and remove boilerplate
2 parents d5f87ad + ae265d7 commit a2864b3

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

form/form_collections.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,9 @@ 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($id, Request $request, EntityManagerInterface $entityManager)
659659
{
660-
$entityManager = $this->getDoctrine()->getManager();
661-
$task = $entityManager->getRepository(Task::class)->find($id);
662-
663-
if (!$task) {
660+
if (null === $task = $entityManager->getRepository(Task::class)->find($id)) {
664661
throw $this->createNotFoundException('No task found for id '.$id);
665662
}
666663

@@ -675,8 +672,7 @@ the relationship between the removed ``Tag`` and ``Task`` object.
675672

676673
$editForm->handleRequest($request);
677674

678-
if ($editForm->isValid()) {
679-
675+
if ($editForm->isSubmitted() && $editForm->isValid()) {
680676
// remove the relationship between the tag and the Task
681677
foreach ($originalTags as $tag) {
682678
if (false === $task->getTags()->contains($tag)) {

0 commit comments

Comments
 (0)