Skip to content
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

#2192 - Allow users to filter Timber default Twig functions #2408

Merged
merged 6 commits into from
Sep 17, 2021

Conversation

nlemoine
Copy link
Member

Hello!

Sorry about the PR flood. I have some spare time so I can finally propose changes I've been thinking/waiting for a long time.

Issue

See #2192

Solution

Provide a filter to remove some functions/filters. (PR is still a draft, I'll implement the same logic for filters if accepted).

Impact

None. Obviously, if you are removing some default functions/filters, you are fully aware of consequences.

Usage Changes

None.

Considerations

Unfortunately, Twig does not support functions/filters removal once added.

Testing

Not yet, I will if/when accepted.

Side note

This PR also makes use of native Twig deprecated option.

Copy link
Member

@gchtr gchtr left a comment

Choose a reason for hiding this comment

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

I like this a lot for a solution to the underlying problem.

Sorry about the PR flood. I have some spare time so I can finally propose changes I've been thinking/waiting for a long time.

Keep them coming ❤️! Your suggestions are very valuable!

This PR also makes use of native Twig deprecated option.

Nice! Good to know this option exists.

lib/Twig.php Show resolved Hide resolved
lib/Twig.php Outdated Show resolved Hide resolved
@nlemoine
Copy link
Member Author

nlemoine commented Jan 15, 2021

Keep them coming ❤️! Your suggestions are very valuable!

Thanks a lot! 😊 I'm a daily Timber user and I thought some improvements I made over projects could benefit to other users and improve the existing code base.

Nice! Good to know this option exists.

I'm not an expert at error handling but it may replace actual deprecations functions?

Helper::deprecated('{{ TimberPost() }}', '{{ get_post() }} or {{ get_posts() }}', '2.0.0');

@gchtr
Copy link
Member

gchtr commented Jan 17, 2021

I'm not an expert at error handling but it may replace actual deprecations functions?

Helper::deprecated('{{ TimberPost() }}', '{{ get_post() }} or {{ get_posts() }}', '2.0.0');

How does the error message look like? Have you tried it out?

The Helper::deprecated() method plugs in with the @expectedDeprecated tags in test DocBlocks, for example here:

/**
* @expectedDeprecated {{ TimberImage() }}
*/
. This makes it possible for us test whether functions also appear as deprecated but still work as expected.

I guess that is the only critical thing to consider here.

As I read in https://twig.symfony.com/doc/2.x/recipes.html#displaying-deprecation-notices, to make this work we would maybe have to install another package. But that would make it even more complex.

@gchtr
Copy link
Member

gchtr commented Jan 17, 2021

Thanks a lot! 😊 I'm a daily Timber user and I thought some improvements I made over projects could benefit to other users and improve the existing code base.

I think that’s why we are all here, after all 😊.

@nlemoine nlemoine marked this pull request as ready for review January 18, 2021 22:56
@nlemoine nlemoine force-pushed the 2.x-filterable-default-functions branch from 69aad25 to 2a64570 Compare January 19, 2021 08:31
@nlemoine
Copy link
Member Author

@gchtr PR updated! I've not included #2284, this can be done a bit later.

@jarednova jarednova added the 2.0 label Jan 20, 2021
@jarednova
Copy link
Member

This is looking really good @nlemoine! (and keep the flood of PRs coming!) Given the amount here that's touching Twig (and Timber) internals, we'll want to make sure this runs through C-I tests before we merge (at the moment our Travis plan + integration are down).

@gchtr I concur with your review notes. Please let me know when this has your ✅ and we can see where we are on the C-I front at that point.

Copy link
Member

@jarednova jarednova left a comment

Choose a reason for hiding this comment

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

This gets my vote. I made just one change to cover for a missing get_users. Since this touches a lot of stuff that @acobster and @gchtr are both active on I'd like one of their reviews as well before we merge

@jarednova jarednova added the Ready for Review Ready for a contrib to take a look at and review/merge label Apr 18, 2021
Copy link
Member

@gchtr gchtr left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍.

I’d leave it a that state and merge it in (@jarednova, I’ll let you do the honors).

I’ll add further iterations in #2419.

Copy link
Collaborator

@acobster acobster left a comment

Choose a reason for hiding this comment

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

This looks great! I didn't run them but the tests look good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 Ready for Review Ready for a contrib to take a look at and review/merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants