@@ -309,7 +309,7 @@ Let's discover how to use Turbo Streams to enhance your `Symfony forms`_::
309
309
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
310
310
use Symfony\Component\HttpFoundation\Request;
311
311
use Symfony\Component\HttpFoundation\Response;
312
- use Symfony\UX\Turbo\Stream\TurboStreamResponse ;
312
+ use Symfony\UX\Turbo\Stream\TurboBundle ;
313
313
314
314
use App\Entity\Task;
315
315
@@ -326,18 +326,23 @@ Let's discover how to use Turbo Streams to enhance your `Symfony forms`_::
326
326
// ... perform some action, such as saving the task to the database
327
327
328
328
// 🔥 The magic happens here! 🔥
329
- if (TurboStreamResponse ::STREAM_FORMAT === $request->getPreferredFormat()) {
329
+ if (TurboBundle ::STREAM_FORMAT === $request->getPreferredFormat()) {
330
330
// If the request comes from Turbo, set the content type as text/vnd.turbo-stream.html and only send the HTML to update
331
- $request->setFormat(TurboStreamResponse ::STREAM_FORMAT);
332
- return $this->render('task/success.stream.html.twig', ['task' => $task], new TurboStreamResponse() );
331
+ $request->setFormat(TurboBundle ::STREAM_FORMAT);
332
+ return $this->render('task/success.stream.html.twig', ['task' => $task]);
333
333
}
334
334
335
335
// If the client doesn't support JavaScript, or isn't using Turbo, the form still works as usual.
336
336
// Symfony UX Turbo is all about progressively enhancing your apps!
337
337
return $this->redirectToRoute('task_success', [], Response::HTTP_SEE_OTHER);
338
338
}
339
339
340
- // Symfony 5.3+
340
+ .. versionadded:: 2.1
341
+
342
+ In versions prior to 2.1, TurboStreamResponse::STREAM_FORMAT was used instead of TurboBundle::STREAM_FORMAT. Also, one had to return a new TurboStreamResponse() object as the third argument for this->render().
343
+
344
+
345
+ // Symfony 5.3+
341
346
return $this->renderForm('task/new.html.twig', [
342
347
'form' => $form,
343
348
]);
0 commit comments