Skip to content

Commit 5eef995

Browse files
authored
Added a message about it was done in version 2.0
I added a helpful message trying to explain that the old version used a different class, and returned a stream response.
1 parent e411a77 commit 5eef995

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Turbo/Resources/doc/index.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Let's discover how to use Turbo Streams to enhance your `Symfony forms`_::
309309
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
310310
use Symfony\Component\HttpFoundation\Request;
311311
use Symfony\Component\HttpFoundation\Response;
312-
use Symfony\UX\Turbo\Stream\TurboStreamResponse;
312+
use Symfony\UX\Turbo\Stream\TurboBundle;
313313
314314
use App\Entity\Task;
315315

@@ -326,18 +326,23 @@ Let's discover how to use Turbo Streams to enhance your `Symfony forms`_::
326326
// ... perform some action, such as saving the task to the database
327327

328328
// 🔥 The magic happens here! 🔥
329-
if (TurboStreamResponse::STREAM_FORMAT === $request->getPreferredFormat()) {
329+
if (TurboBundle::STREAM_FORMAT === $request->getPreferredFormat()) {
330330
// 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]);
333333
}
334334

335335
// If the client doesn't support JavaScript, or isn't using Turbo, the form still works as usual.
336336
// Symfony UX Turbo is all about progressively enhancing your apps!
337337
return $this->redirectToRoute('task_success', [], Response::HTTP_SEE_OTHER);
338338
}
339339

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+
341346
return $this->renderForm('task/new.html.twig', [
342347
'form' => $form,
343348
]);

0 commit comments

Comments
 (0)