Skip to content

Conversation

@qdequippe
Copy link
Contributor

@qdequippe qdequippe force-pushed the mercure-twig-runtime branch from d53af01 to 43f8bd4 Compare June 16, 2025 10:20
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Removing a public method from a class is a breaking change, but I think we can make it of the next 0.minor version.

The extension attributes added in Twig 3.21.0 allows to create lazy extension with a single class. I recommend this approach.

The MercureBundle must also be updated to enable autoconfiguration (or add both twig.attribute_extension and twig.runtime tags): https://github.com/symfony/mercure-bundle/blob/main/src/DependencyInjection/MercureExtension.php#L270-L274

*
* @return string The URL of the hub with the appropriate "topic" query parameters (if any)
*/
public function mercure($topics = null, array $options = []): string
Copy link
Member

Choose a reason for hiding this comment

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

You could keep this function in this class and use the #[TwigFunction] attribute to make this extension lazy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qdequippe qdequippe force-pushed the mercure-twig-runtime branch 2 times, most recently from 6cdd947 to 3000654 Compare August 15, 2025 17:15
# Conflicts:
#	src/Twig/MercureExtension.php
@dunglas dunglas force-pushed the mercure-twig-runtime branch from 3000654 to 048e351 Compare November 20, 2025 13:20
@dunglas dunglas merged commit 9f50ed1 into symfony:main Nov 20, 2025
10 checks passed
@qdequippe qdequippe deleted the mercure-twig-runtime branch November 20, 2025 13:26
@Kocal
Copy link
Member

Kocal commented Nov 22, 2025

Hi!

Unfortunately it brokes Symfony UX test suite, see symfony/ux#3185:

Caused by
Error: Call to undefined method Twig\Extension\AttributeExtension::mercure()

/Users/kocal/workspace-os/symfony-ux/src/Turbo/src/Bridge/Mercure/TurboStreamListenRenderer.php:74
/Users/kocal/workspace-os/symfony-ux/src/Turbo/src/Twig/TurboRuntime.php:56
/Users/kocal/workspace-os/symfony-ux/src/Turbo/tests/app/var/cache/test/twig/a6/a6bf9eb373b97e9f3553121cb9f84f50.php:48
/Users/kocal/workspace-os/symfony-ux/src/Turbo/vendor/twig/twig/src/Template.php:402
/Users/kocal/workspace-os/symfony-ux/src/Turbo/vendor/twig/twig/src/Template.php:358
/Users/kocal/workspace-os/symfony-ux/src/Turbo/vendor/twig/twig/src/Template.php:373
/Users/kocal/workspace-os/symfony-ux/src/Turbo/vendor/twig/twig/src/TemplateWrapper.php:51
/Users/kocal/workspace-os/symfony-ux/src/Turbo/tests/Bridge/Mercure/TurboStreamListenRendererTest.php:30

How can we migrate this code?

$mercure = $this->twig->getExtension(MercureExtension::class);
if ($eventSourceOptions['withCredentials'] ?? false) {
    $eventSourceOptions['subscribe'] ??= $topics;
    $controllerAttributes['withCredentials'] = true;
}
$mercure->mercure($topics, $eventSourceOptions);

Thanks!

@GromNaN
Copy link
Member

GromNaN commented Nov 22, 2025

@Kocal the MercureExtension is now registered as a Twig runtime.

@Kocal
Copy link
Member

Kocal commented Nov 22, 2025

Thanks!

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.

4 participants