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

V2 site overwrite magic __call method #2798

Merged
merged 5 commits into from Oct 26, 2023
Merged

Conversation

Levdbas
Copy link
Member

@Levdbas Levdbas commented Sep 15, 2023

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 the meta() method. Since the meta() 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?

@Levdbas
Copy link
Member Author

Levdbas commented Sep 15, 2023

@gchtr , Directly created a PR for this. Should we add this to the 2.0 release?

@jrathert
Copy link
Contributor

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 would be in favor of deprecating these magic methods in the future as well so people (including myself) will learn the difference.

I fully support that.

@coveralls
Copy link

coveralls commented Sep 15, 2023

Coverage Status

coverage: 88.528% (+0.003%) from 88.525% when pulling c33ec4d on v2-site-overwrite-call-method into 5149aa7 on 2.x.

src/Site.php Outdated Show resolved Hide resolved
@Levdbas Levdbas added the 2.0 label Sep 29, 2023
@gchtr gchtr added the bug label Oct 16, 2023
@gchtr
Copy link
Member

gchtr commented Oct 16, 2023

@gchtr , Directly created a PR for this. Should we add this to the 2.0 release?

Thanks for the PR. Yes, because this actually fixes a bug I’d say we should include it in the 2.0 release.

Testing

No, should it be tested?

@Levdbas I think it would be good if we could add a test for this. Do you need help with that?

@Levdbas
Copy link
Member Author

Levdbas commented Oct 17, 2023

@gchtr , Directly created a PR for this. Should we add this to the 2.0 release?

Thanks for the PR. Yes, because this actually fixes a bug I’d say we should include it in the 2.0 release.

Testing

No, should it be tested?

@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 ?

Copy link
Member

@nlemoine nlemoine left a 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 🙂

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 all looks fine, including the test 👍. Thanks, @Levdbas

@gchtr gchtr merged commit dc49063 into 2.x Oct 26, 2023
26 of 30 checks passed
@Levdbas Levdbas deleted the v2-site-overwrite-call-method branch November 9, 2023 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants