Skip to content

Commit 01e5f81

Browse files
committed
documentation #3491 [Turbo] Restructure and standardize the documentation (seb-jean)
This PR was merged into the 3.x branch. Discussion ---------- [Turbo] Restructure and standardize the documentation | Q | A | -------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Documentation? | yes <!-- required for new features, or documentation updates --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Over the past few days, I took the time to thoroughly rework the Symfony UX Turbo documentation to improve its clarity, consistency and quality. Changes: - Unify all code examples around a single Task entity thread (controller, form, templates) - Split the monolithic index.rst into focused sub-pages (`custom-transport`, `multiple-submit-buttons`, `multiple-transports`, `resetting-form`, `testing`, `webpack-encore`) - Apply Symfony documentation standards - Add missing namespace, use statements and `#[Route]` attributes in PHP examples - Fix trailing commas in PHP arrays - Add "Minimal Frame Layout" section with ``@Turbo`/layouts/frame.html.twig` - Add "Custom Action" section for `<twig:Turbo:Stream>` and `TurboStreamResponse::action()` Commits ------- 5257a90 [Turbo] Restructure and standardize the documentation
2 parents 77d14a9 + 5257a90 commit 01e5f81

9 files changed

Lines changed: 903 additions & 637 deletions

src/Turbo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ or any other transports to broadcast DOM changes to all currently connected user
1212
You're in a hurry? Take a look at [the chat example](https://symfony.com/bundles/ux-turbo/current/index.html#chat-example)
1313
to discover the full potential of Symfony UX Turbo.
1414

15-
Or watch the [Turbo Screencast on SymfonyCasts](https://symfonycasts.com/screencast/turbo).
15+
Or watch the [Symfony UX Turbo screencast series](https://symfonycasts.com/screencast/turbo).
1616

1717
**This repository is a READ-ONLY sub-tree split**. See
1818
https://github.com/symfony/ux to create issues or submit pull requests.

src/Turbo/doc/custom-transport.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
How to Register a Custom Transport
2+
==================================
3+
4+
If you prefer using another protocol than Mercure, you can create custom
5+
transports::
6+
7+
// src/Turbo/Broadcaster.php
8+
namespace App\Turbo;
9+
10+
use Symfony\UX\Turbo\Attribute\Broadcast;
11+
use Symfony\UX\Turbo\Broadcaster\BroadcasterInterface;
12+
13+
class Broadcaster implements BroadcasterInterface
14+
{
15+
public function broadcast(object $entity, string $action): void
16+
{
17+
// Called every time an object marked with #[Broadcast] changes
18+
$attribute = (new \ReflectionClass($entity))
19+
->getAttributes(Broadcast::class)[0] ?? null;
20+
// ...
21+
}
22+
}
23+
24+
Then a stream source renderer::
25+
26+
// src/Turbo/MyStreamSourceRenderer.php
27+
namespace App\Turbo;
28+
29+
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
30+
use Symfony\UX\Turbo\StreamSourceRendererInterface;
31+
32+
#[AsTaggedItem(index: 'my-transport')]
33+
class MyStreamSourceRenderer implements StreamSourceRendererInterface
34+
{
35+
public function render(string|object|array $topics, array $options = []): string
36+
{
37+
$url = 'https://my-transport.example.com/subscribe?topic='.$topics;
38+
$private = $options['private'] ?? false;
39+
40+
return \sprintf(
41+
'<my-custom-stream-source src="%s"%s></my-custom-stream-source>',
42+
htmlspecialchars($url, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'),
43+
$private ? ' private' : '',
44+
);
45+
}
46+
}
47+
48+
The broadcaster must be registered as a service tagged with
49+
``turbo.broadcaster`` and the stream source renderer must be tagged with
50+
``turbo.stream_source_renderer``. If you enabled `autoconfigure option`_
51+
(it's the case by default), these tags will be added automatically because
52+
these classes implement the ``BroadcasterInterface`` and
53+
``StreamSourceRendererInterface`` interfaces.
54+
55+
.. _`autoconfigure option`: https://symfony.com/doc/current/service_container.html#the-autoconfigure-option

0 commit comments

Comments
 (0)