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
Twig functions becoming internal #4040
Comments
Just my two cents here: that those functions became internal is perfectly legit; that they became internal in the context of a minor version is very controversial and requires some explanation. |
They are deprecated, but still here, that's the way we work for Symfony and Twig. We first deprecate so that you've time to upgrade to the new way, and we then remove it in the next major. |
Thanks for the clarification. I stand corrected. 🙏 |
Perhaps I made this unclear by using the old names, I understand they have been deprecated and there are replacements, my concern is those replacements are marked with Twig/src/Extension/EscaperExtension.php Lines 170 to 182 in ad93431
It seems crazy to me that I'm not supposed to use Twig to escape content I generate in a custom Twig extension. |
@cs278 I totally agree. A method that was not marked as internal - and thus that was implicitly public - disappeared and it's replacement was marked internal, all of this during a minor version change. |
The non-internal functions did not disappear. They are marked as deprecated, which means they still work until Twig 4.0. And the new internal methods are not meant to be replacements for public usages of those functions. The replacement is to stop using Twig internal APIs directly. |
So what is the migration path then? Your reply seems to suggest there is a different way of calling these from an extension but I cannot find anything in the documentation or changelog, clearly I'm not alone in missing this knowledge: |
Hello, Regarding the 3.9 changes I got a problem where a publicly available function I think this breaking change should at least be mentioned in the changelog and being in a mayor release. Am I missing something on this? Thank you |
|
I see, that is completely reasonable. Unfortunately the |
Thank you all for the feedback. One option would be to review all the new internal methods and determine which ones should be part of the public API because they are useful when creating Twig extensions. For instance, the |
#4044 is a first step that would allow extracting a public API for some methods. |
There is no reason to make
|
Yeah I was on the fence about that the only value is the exception it throws for you, so probably not worth it.
👍 Good point.
Indeed limited use, I was thinking if you wanted to remove white space from any generated markup. |
I'd like to have access to
|
why not using |
Indeed you are right about For the case of There is also the fact of being able to control the |
Support for using a list of templates is also available in the public API by using If there is really a need for the equivalent of the
This is not relevant. The implementation of |
Ok good point, I agree, this point cover the need, thanks.
I agree, in point of view of implementation is not relevant. It was just a remark for an external point of view. |
It also seems to break https://twig.symfony.com/doc/3.x/filters/format_datetime.html - I'm getting an "Call to undefined method Twig\Extension\CoreExtension::dateConverter()" in |
@lostfocus |
Thanks! |
It might even deserve its own standalone symfony component. Because proper escaping is not easy and this function could also be useful outside of twig. |
For escaping, can you have a look at #4055 and give me your feedback? |
I think #4066 finally closes this issue. |
Since 3.9 it appears all of Twigs filter/functions underlying PHP implementations are marked as internal, could this be reconsidered in some cases? I'm assuming internal means the signature might change in non backwards compatible ways, if it doesn't I guess this isn't really a problem.
The two cases that affect myself are
twig_escape_filter
andtwig_date_converter
.For example I have a filter which generates some HTML:
I've consulted the documentation but it doesn't seem to offer any examples on how to deal with more complicated situations such as this, so perhaps this is the wrong way of doing it but it's worked since Twig 1.x.
Likewise with dates I have some custom filters to limit developers to a limited set of predefined formats, the filters look a bit like this:
Being able to use
twig_date_converter
means the Twig timezone setting works as expected.I did some searching on GitHub and found numerous other cases.
https://github.com/theoboldt/juvem/blob/98af699c95c46e919dc1690ab1730754ebd65141/app/src/AppBundle/Twig/Extension/CustomFieldValue.php#L244
https://github.com/njh/twig-html-helpers/blob/d3dc45f6a9ac67512126c02a8d11c7a09889d942/lib/Twig/Extension/HTMLHelpers.php#L53
https://github.com/symfony/ux/blob/d4df61465571381ffa8692268fca6acd09b32feb/src/StimulusBundle/src/Dto/StimulusAttributes.php#L223
https://github.com/symfony/ux/blob/d4df61465571381ffa8692268fca6acd09b32feb/src/LiveComponent/src/Util/LiveAttributesCollection.php#L121
https://github.com/studiometa/twig-toolkit/blob/9e73108d84c11171ef69fd34dd8946afee8e9a5c/src/Helpers/Html.php#L209
https://github.com/mautic/mautic/blob/175ceac9098f0b9515f34820a0eafd924877864b/plugins/MauticFocusBundle/Model/FocusModel.php#L183
https://github.com/symfony/symfony/blob/a2d03c548c2e897be78504fd4a389bb7eb41e756/src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php#L116
https://github.com/drupal/drupal/blob/449f6fbf7c058988ba6f18a8e70cba4bf6639941/core/lib/Drupal/Core/Template/TwigExtension.php#L464
https://github.com/phpbb/phpbb/blob/4c721de243967ed4cf372caef4e54142ee6bcf6c/phpBB/phpbb/template/twig/extension.php#L215
https://github.com/IISHF/web2019/blob/0ca849abf7f247abfcf01521b6cdeee22e1d637b/src/Infrastructure/Twig/DateExtension.php#L108-L115
https://github.com/imarc/cms/blob/ef349e03202628638247a71158ff04c49da2068a/src/web/twig/Extension.php#L482
https://github.com/twigphp/intl-extra/blob/00cd46d7860cf7e814f73b290edf32801a47cafc/IntlExtension.php#L282
The text was updated successfully, but these errors were encountered: