-
-
Notifications
You must be signed in to change notification settings - Fork 600
Items have magic properties and methods #5297
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
|
You are making it too easy! :) These changes are brilliant. |
This was referenced Feb 17, 2022
jasonvarga
added a commit
that referenced
this pull request
Feb 21, 2022
- Remove the has/get/set/data methods so they delegate to ContainsData which does the same thing. - The data method will always return a collection. - The data method used to filter out fields that weren't in the blueprint. This was a leftover thing from v2 before we moved to v3 style validation. Now it won't do any filtering. This goes along with #5297 but moving into its own PR to avoid noise there.
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With all the recent updates to working with items in Blade to make it seem more like eloquent, we thought why just make a wrapper? Let's make the entry/term/etc classes have magic properties and methods like eloquent models.
Overview
Magic properties
Calling
$entry->somethingwill get the evaluated augmented value. ie. It will not be wrapped in aValueclass.Magic methods
Calling
$entry->something()will get a query builder if thesomethingfield if a fieldtype that augments to a query builder (e.g. anentriesfieldtype). This will allow you to continue chaining a query, just like an Eloquent Model relationship.Breaking Changes
There are two breaking changes, both pretty minor.
First is the
ContainsDatatrait. If you were using that, the__get()method has been removed.If you were also using the
HasAugmentedDataorHasAugmentedInstancetraits, it was moved in there, so no change is necessary. Otherwise, you can add this to your class:Next change is that previously calling a property would get the raw data on that entry, without any fallback logic.
Now, it'll consider the entry itself, any origin entries, the collection cascade, etc.
It's only really going to affect you in two situations:
If you were using property access on a field that has a different end result if you were to augment it.
For example, an
entriesfield.For basic fields, like
text,toggle, etc, there's no change:If you were intentionally wanting the value on the entry, without factoring in fallbacks to origin entries or collection cascade:
To get the previous behavior, you can do
$entry->get('fieldname')Todo: