Skip to content

Symfony UX Turbo: content negotiation and Doctrine integration #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 77 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Mar 2, 2021

Q A
Bug fix? no
New feature? no
Tickets n/a
License MIT

This PR introduces an integration of Hotwire Turbo with Symfony. It has been developed and tested over the past few months by @tgalopin, @nicolas-grekas, @chalasr, @weaverryan and me. It is complementary with #61 (#61 focuses on the integration with Twig while this one focuses on higher level features, #61 will have to be rebased on top of this one).

The best way to discover the features provided by this new component is to read the provided README file. To summarize, it provides:

  • an integration with Mercure to stream page changes to all connected browsers from the controller. It's also possible to plug other transports.
  • an integration with the Form component allowing to send changes to apply to the existing DOM in response to a POST
  • a new PHP 8 attribute (#[Broadcast]): when a Doctrine entity is marked with this attribute, all changes made to it will be broadcasted in real time to all connected clients, and the DOM will instantly update consequently (a Twig template defined the operations to apply to the existing DOM tree). An extension point is available to plug other persistence systems
  • a sample app, including Panther tests (used as functional tests for the bundle itself)
  • a template for GitHub Actions workflow

TODO:

dunglas and others added 19 commits December 24, 2020 18:04
refactor: decouple Broadcast from Twig and Mercure
ci: add PHP-CS-Fixer and PHPStan
* test: add UI tests

* Fix @nicolas-grekas' review
This will make it so that an invalid form is rendered correctly
* /Users/dunglas/workspace/hotwire-bundle:
  prepare merge in symfony/ux
  tweaking how the cloned form is used in the docs (symfony#12)
  updating stream media type to match changes in Turbo (symfony#11)
  ci: setup GitHub Actions (symfony#8)
  fix: regressions introduced in #5 (symfony#7)
  Relax minimum php version (#5)
  fix: various quality improvements (symfony#6)
  test: add UI tests (#4)
  ci: add PHPStan
  ci: add PHP-CS-Fixer
  refactor: broadcast template conventions and config
  refactor: decouple Broadcast from Twig and Mercure
  feat: initial implementation
dunglas and others added 6 commits March 26, 2021 17:11
Add $options to BroadcastListener::broadcast()
* 'turbo' of github.com:dunglas/ux:
  Add $options to BroadcastListener::broadcast()
  -
  Tweaks and review
@dunglas dunglas closed this Mar 27, 2021
@dunglas dunglas reopened this Mar 27, 2021
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid!


if ($this->doctrine && $em = $this->doctrine->getManagerForClass($entityClass)) {
return $em->getClassMetadata($entityClass)->getIdentifierValues($entity);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

chalasr added a commit to symfony/symfony that referenced this pull request Mar 30, 2021
…r to generate fragments URL (dunglas)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix n/a
| License       | MIT
| Doc PR        | todo

This PR adds a new helper to generate raw fragment URL. Fragments will be useful to generate lazy frames with Symfony UX Turbo (symfony/ux#64). This will also be convenient when using hinclude, ESI etc in case you want full control over the generated HTML.
This is also more in sync with the new best practices we apply in the form component (generate the HTML by yourself instead of using Twig helpers hiding the HTML elements).

Example:

```html
<turbo-frame id="set_aside_tray" src="{{ fragment_uri(controller('Symfony\Bundle\FrameworkBundle\Controller', {template: "foo.html.twig"})) }}">
  <img src="/icons/spinner.gif">
</turbo-frame>
```

Commits
-------

5d29d76 [FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Mar 30, 2021
…r to generate fragments URL (dunglas)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix n/a
| License       | MIT
| Doc PR        | todo

This PR adds a new helper to generate raw fragment URL. Fragments will be useful to generate lazy frames with Symfony UX Turbo (symfony/ux#64). This will also be convenient when using hinclude, ESI etc in case you want full control over the generated HTML.
This is also more in sync with the new best practices we apply in the form component (generate the HTML by yourself instead of using Twig helpers hiding the HTML elements).

Example:

```html
<turbo-frame id="set_aside_tray" src="{{ fragment_uri(controller('Symfony\Bundle\FrameworkBundle\Controller', {template: "foo.html.twig"})) }}">
  <img src="/icons/spinner.gif">
</turbo-frame>
```

Commits
-------

5d29d76612 [FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Mar 30, 2021
…r to generate fragments URL (dunglas)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix n/a
| License       | MIT
| Doc PR        | todo

This PR adds a new helper to generate raw fragment URL. Fragments will be useful to generate lazy frames with Symfony UX Turbo (symfony/ux#64). This will also be convenient when using hinclude, ESI etc in case you want full control over the generated HTML.
This is also more in sync with the new best practices we apply in the form component (generate the HTML by yourself instead of using Twig helpers hiding the HTML elements).

Example:

```html
<turbo-frame id="set_aside_tray" src="{{ fragment_uri(controller('Symfony\Bundle\FrameworkBundle\Controller', {template: "foo.html.twig"})) }}">
  <img src="/icons/spinner.gif">
</turbo-frame>
```

Commits
-------

5d29d76612 [FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL
symfony-splitter pushed a commit to symfony/twig-bridge that referenced this pull request Mar 30, 2021
…r to generate fragments URL (dunglas)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix n/a
| License       | MIT
| Doc PR        | todo

This PR adds a new helper to generate raw fragment URL. Fragments will be useful to generate lazy frames with Symfony UX Turbo (symfony/ux#64). This will also be convenient when using hinclude, ESI etc in case you want full control over the generated HTML.
This is also more in sync with the new best practices we apply in the form component (generate the HTML by yourself instead of using Twig helpers hiding the HTML elements).

Example:

```html
<turbo-frame id="set_aside_tray" src="{{ fragment_uri(controller('Symfony\Bundle\FrameworkBundle\Controller', {template: "foo.html.twig"})) }}">
  <img src="/icons/spinner.gif">
</turbo-frame>
```

Commits
-------

5d29d76612 [FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL
nicolas-grekas and others added 10 commits March 30, 2021 16:59
* turbo-mercure:
  run yarn tests for all workspaces
  -
  -
  -
  fix cs
  fix build
  re-add main package.json
  Fix JS
  Move Mercure integration to a dedicated bridge
@nicolas-grekas
Copy link
Member

Continued in #71

tgalopin added a commit that referenced this pull request Mar 30, 2021
…ation (dunglas)

This PR was merged into the main branch.

Discussion
----------

Symfony UX Turbo: content negotiation and Doctrine integration

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| Tickets       | Fix #64
| License       | MIT

Same as #64, just squashed. See there for details and history.

Commits
-------

95d5f00 Symfony UX Turbo: content negotiation and Doctrine integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants