php-translation / symfony-bundle

Symfony integration for Translations
MIT License
327 stars 93 forks source link

[EditInPlace] is_safe_callback is compiled in the Twig cache #260

Open damienalexandre opened 6 years ago

damienalexandre commented 6 years ago

https://github.com/php-translation/symfony-bundle/pull/102 introduce the is_safe_callback option instead of the old is_safe => ['html'] that was causing some issues and unexpected behavior (changing the way Symfony does the escaping by default).

But there is an issue with this method as Twig use this method during the compile phase. So the generated templates never call the callback again.

So on a fresh and empty cache:

Enabling and disabling the Edit In Place (via the Activator service) does not re-compile Twig cache.

There is two issues:

Some possible solutions:

odolbeau commented 4 years ago

What's the drawback of the first solution (marking the return of the twig function as always safe)?

damienalexandre commented 4 years ago

The main drawback is compatibility with Symfony native translation system. If we go "always safe", there will be no escaping on translations, ever. But we only want to disable escaping when we are in the "Edit" mode.