Skip to content

Commit af1cb41

Browse files
committed
feature #895 [make:crud] send the proper HTTP status codes and use renderForm() when available (dunglas)
This PR was merged into the 1.0-dev branch. Discussion ---------- [make:crud] send the proper HTTP status codes and use renderForm() when available This makes `make:crud` compatible with Symfony Turbo by default. Commits ------- 0643e51 crud: send the proper HTTP status codes and use renderForm() when available
2 parents 243a36c + 0643e51 commit af1cb41

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Maker/MakeCrud.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\Inflector\Inflector as LegacyInflector;
1616
use Doctrine\Inflector\InflectorFactory;
1717
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
18+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1819
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1920
use Symfony\Bundle\MakerBundle\DependencyBuilder;
2021
use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper;
@@ -168,6 +169,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
168169
'entity_var_singular' => $entityVarSingular,
169170
'entity_twig_var_singular' => $entityTwigVarSingular,
170171
'entity_identifier' => $entityDoctrineDetails->getIdentifier(),
172+
'use_render_form' => method_exists(AbstractController::class, 'renderForm'),
171173
],
172174
$repositoryVars
173175
)

src/Resources/skeleton/crud/controller/Controller.tpl.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,20 @@ public function new(Request $request): Response
6666
$entityManager->persist($<?= $entity_var_singular ?>);
6767
$entityManager->flush();
6868

69-
return $this->redirectToRoute('<?= $route_name ?>_index');
69+
return $this->redirectToRoute('<?= $route_name ?>_index', [], Response::HTTP_SEE_OTHER);
7070
}
7171

72+
<?php if ($use_render_form) { ?>
73+
return $this->renderForm('<?= $templates_path ?>/new.html.twig', [
74+
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
75+
'form' => $form,
76+
]);
77+
<?php } else { ?>
7278
return $this->render('<?= $templates_path ?>/new.html.twig', [
7379
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
7480
'form' => $form->createView(),
7581
]);
82+
<?php } ?>
7683
}
7784

7885
<?php if ($use_attributes) { ?>
@@ -104,13 +111,20 @@ public function edit(Request $request, <?= $entity_class_name ?> $<?= $entity_va
104111
if ($form->isSubmitted() && $form->isValid()) {
105112
$this->getDoctrine()->getManager()->flush();
106113

107-
return $this->redirectToRoute('<?= $route_name ?>_index');
114+
return $this->redirectToRoute('<?= $route_name ?>_index', [], Response::HTTP_SEE_OTHER);
108115
}
109116

117+
<?php if ($use_render_form) { ?>
118+
return $this->renderForm('<?= $templates_path ?>/edit.html.twig', [
119+
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
120+
'form' => $form,
121+
]);
122+
<?php } else { ?>
110123
return $this->render('<?= $templates_path ?>/edit.html.twig', [
111124
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
112125
'form' => $form->createView(),
113126
]);
127+
<?php } ?>
114128
}
115129

116130
<?php if ($use_attributes) { ?>
@@ -128,6 +142,6 @@ public function delete(Request $request, <?= $entity_class_name ?> $<?= $entity_
128142
$entityManager->flush();
129143
}
130144

131-
return $this->redirectToRoute('<?= $route_name ?>_index');
145+
return $this->redirectToRoute('<?= $route_name ?>_index', [], Response::HTTP_SEE_OTHER);
132146
}
133147
}

0 commit comments

Comments
 (0)