Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Field item properties can be accessed via magic method.
This is thanks to FieldItemBase::__get().
IMO, magic __get() is only useful if the IDE can determine the return type.
Fortunately this is easy to achieve. E.g. like this on EntityReferenceItem:
namespace Drupal\Core\Field\Plugin\Field\FieldType;
[..]
/**
[..]
*
* @property string|int $target_id
* @property EntityInterface $entity
*/
class EntityReferenceItem [..] {
There are probably more magic __get() in other places. But for this issue let us focus on field items.
Comment | File | Size | Author |
---|---|---|---|
#30 | 2901435-30.patch | 11.22 KB | _utsavsharma |
| |||
#30 | interdiff_d10.txt | 11.22 KB | _utsavsharma |
#29 | 2901435-nr-bot.txt | 8.35 KB | needs-review-queue-bot |
#19 | 2901435-19.patch | 11.09 KB | harsha012 |
#17 | 2901435-17.patch | 4.18 KB | harsha012 |
Comments
Comment #2
ioana apetri CreditAttribution: ioana apetri at OPTASY commentedAs I speak with @donquixote, I created this patch for the documenting the field item properties from this class. I will go to find out other classes which need this kind of updates.
Comment #3
donquixote CreditAttribution: donquixote commentedFrom my side this patch looks good. Thanks @yo30!
I am curious what other people think.
Comment #4
Venkatesh Rajan.J CreditAttribution: Venkatesh Rajan.J as a volunteer and at Drupal Partners commentedComment #5
Venkatesh Rajan.J CreditAttribution: Venkatesh Rajan.J as a volunteer and at Drupal Partners commented@yo30,
Thanks for the patch. Your patch applied cleanly. PFA screenshots for the same.
Comment #7
Ivan Berezhnov CreditAttribution: Ivan Berezhnov as a volunteer and at Drupal Ukraine Community for Levi9 commentedComment #8
ioana apetri CreditAttribution: ioana apetri at OPTASY commentedwhat represents CSKyiv18 tag?:)
Comment #9
donquixote CreditAttribution: donquixote commentedI think this is just a bogus test fail which has nothing to do with this patch.
Queued a re-test.
Comment #10
donquixote CreditAttribution: donquixote commentedI imagine CSKyiv18 is an event in Kyiv (Kiev) in Ukraine?
Comment #11
Venkatesh Rajan.J CreditAttribution: Venkatesh Rajan.J as a volunteer and at Drupal Partners commented#2 looks good. Assigning the ticket to RTBC.
Comment #12
larowlanHi
I think this is a good idea, but if we're going to do it, we should do it for all field types, not just entity reference.
Thanks
Lee
Comment #13
larowlan@Venkatesh Rajan.J, please don't paste screenshots of patches applying, we have automated testing that will tell us that.
Thanks
Comment #14
larowlanComment #15
snehi CreditAttribution: snehi as a volunteer and at Publicis Sapient for Publicis Sapient commentedHi @larolwan can you please just elaborate that for which files you are mentioning to ?
Thanks
Comment #17
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedTried to do it for other field type.
Comment #18
hchonovStill only a few of the field items are covered. Try to search by regex in your IDE for
namespace(.*)Plugin\\Field\\FieldType
and you'll find all the field items in core and in the core modules.Comment #19
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedadded the @property to all field type
Comment #29
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #30
_utsavsharma CreditAttribution: _utsavsharma at OpenSense Labs for DrupalFit commentedPatch for 10.1.x.