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
V2 site overwrite magic __call method #2798
Conversation
@gchtr , Directly created a PR for this. Should we add this to the 2.0 release? |
I fully support that. |
Thanks for the PR. Yes, because this actually fixes a bug I’d say we should include it in the 2.0 release.
@Levdbas I think it would be good if we could add a test for this. Do you need help with that? |
Alright I created my first test and used the timber compile_string method for that since this call method is only meant to be used directly from Twig. Removing the __call overwrite in the site class causes the test to fail because of the deprecation notice, so I think we are good here. Any feedback on how to improve this test @gchtr ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Levdbas! This looks good to me and congrats on writing test 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks fine, including the test 👍. Thanks, @Levdbas
Related:
Issue
When calling a site option that does not have it's own method, like
site.home
. Timber would use the magic__call
method from the Core class. This magic method by defaults calls themeta()
method. Since themeta()
method was deprecated in the site class (#1700) the magic__call
method throws a deprecation notice.Solution
Overwrite the __call method in Site.php and call the appropriate
option()
method instead.Impact
Less questions on why deprecation notices are thrown.
Usage Changes
None.
Considerations
Sometimes it's hard to wrap your head around what are actual instantiated data in Timber and what is called via these magic methods. I always thought that
{{ site.home }}
was a valid method, but when digging deeper I found out that you should call{{ site.link }}
I would be in favor of deprecating these magic methods in the future as well so people (including myself) will learn the difference.
Testing
No, should it be tested?