I am not sure what to report and how to do it. This is not a rage issue. This is factual: I am writing a patch and I found that I somehow broke the default values of the instance. It's in the config YAML but it doesn't go as far as the widget.
Now. I had my share of Drupal (I even wrote small parts of it ;) ) and PHP and stuff and although I had my grievances with other parts of D8 but eventually I found my way around (even if I really didn't like it). But this, here's absolutely no way to figure out how a piece of data gets from storage to screen (eventually I figured that the default value is coming from field_entity_create).
For example, watch this beauty from field storage:
$entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;
If you vaguely know how the entity-field API now works, you'd expect this to involve magic setters. Wrong. It uses the magic getters which return a reference (!) and so the equal sign can write directly into that... Note that EntityNG also has &__get().
This needs a very, very serious documentation effort to make it viable.
webchick asked to make this actionable. Well:
- How does the system determine what properties an entity object has? Like, $node.
- How do those properties get populated?
- Given the amount of magic, any caveats retrieving those properties
Comment | File | Size | Author |
---|---|---|---|
#34 | content-entity-1977266-34.patch | 15.58 KB | tim.plunkett |
#31 | interdiff.txt | 587 bytes | star-szr |
#31 | 1977266-31.patch | 14.32 KB | star-szr |
#30 | 1977266-30.patch | 13.75 KB | star-szr |
#24 | entity_get_not_by_ref-1977266-24.patch | 14.31 KB | effulgentsia |
Comments
Comment #1
msonnabaum CreditAttribution: msonnabaum commentedDocumentation is not the answer here.
Comment #1.0
msonnabaum CreditAttribution: msonnabaum commentedUpdated issue summary.
Comment #1.1
chx CreditAttribution: chx commentedUpdated issue summary.
Comment #2
fagoYou arguing about the complexity of the BC-mode. Yes BC-mode is unnecessary complex as it translates from an old to a new API. Yes, that's very hard to follow and understand, but it's not supposed to stay.
Comment #3
fagoberdir suggested to add the new variant here, so I do:
or just
if the langcode is default language anyway.
Comment #4
catchIsn't this just "remove the backwards compatibility layer" if so that's #1818580: [Meta] Convert all entity types to the new Entity Field API.
Comment #5
chx CreditAttribution: chx commentedJust because the BC layer makes it harder it doesn't mean the NG system relying on &__get will go away?
Comment #6
fago>NG system relying on &__get
The NG system does not rely on that?
Comment #7
dcam CreditAttribution: dcam commentedhttp://drupal.org/node/1427826 contains instructions for updating the issue summary with the summary template.
Comment #8
catchBack to needs more info. There's still nothing specific here that's not due to the backwards compatibility layer.
Comment #8.0
catchUpdated issue summary.
Comment #9
effulgentsia CreditAttribution: effulgentsia commentedTagging to get this to show up in all the relevant lists.
Comment #10
chx CreditAttribution: chx commentedContentEntityBase has public function &__get($name) -- I am not sure whether that's used internally or just for $node->foo but then why it's a reference?
Comment #11
effulgentsia CreditAttribution: effulgentsia commentedSure. Now that we don't need it for BC support, let's resolve that @todo.
Comment #13
BerdirNo, that's not possible as long as we have code the one mentioned in the @todo, I left that there for a reason :)
Comment #14
effulgentsia CreditAttribution: effulgentsia commentedWell, let's at least see how far the rabbit hole goes.
Comment #15
BerdirSure :)
The translation part is handled in #1916790: Convert translation metadata into regular entity fields, no idea what to do with ->content.
Comment #17
effulgentsia CreditAttribution: effulgentsia commentedComment #18
effulgentsia CreditAttribution: effulgentsia commentedExpanding the scope of this patch to track down other cases of non-field properties.
Comment #20
effulgentsia CreditAttribution: effulgentsia commentedComment #22
effulgentsia CreditAttribution: effulgentsia commentedComment #24
effulgentsia CreditAttribution: effulgentsia commentedComment #27
effulgentsia CreditAttribution: effulgentsia commentedGrrrr. I give up. Anyone have an idea how to reproduce bot's installation failure?
Comment #28
haydeniv CreditAttribution: haydeniv commented24: entity_get_not_by_ref-1977266-24.patch queued for re-testing.
Comment #30
star-szrI wasn't able to reproduce the install fail but here is a reroll for a conflict with #2028037: Expand FeedInterface with methods.
Comment #31
star-szrMissed this added property, going to cancel the last one.
Comment #34
tim.plunkettRerolled. No interdiff possible.
Comment #36
Berdir#18:
That's quite a different beast and the patch did not install successfully since then. Can we go back to the patch in #17 for this issue?
The ability to support non-fields is what separates __get() from get(), if we don't want that, we can simply call get() from there. But IMHO, that's a different issue.
I'd rather have support for non-fields than weird public properties like the recent pages have.
Comment #37
tim.plunkettWell I can install locally, so I don't know where to go from here.
In this last patch, I tried to document where the non-fields were called from.
In the ConfigEntity world, we removed as many of these as possible, and use get()/set() explicitly with protected properties...
Comment #38
BerdirSo can I, but wouldn't be the first time bot somehow works differently. Although we can try again now that 8.x is running on 5.4.
But I'm worried that doing it all at once is going to delay this patch a lot. And as mentioned, then we just need to pass to $this->get() in __get().
Comment #39
Berdir34: content-entity-1977266-34.patch queued for re-testing.
Comment #41
tim.plunkettNevermind then.
Comment #42
BerdirActually, even going back to #17 doesn't help much. Because that only passes with having public properties that are used elsewhere, some in optional modules.
What we need is actual solutions for the values that were identified there. For translatoin, we have #1916790: Convert translation metadata into regular entity fields.
I'm not sure what to do about the others?
Comment #43
effulgentsia CreditAttribution: effulgentsia commentedSo, with regular PHP objects, you can do
$foo->some_undeclared_array[] = 'additional value'
. The question is, do we want to allow the same for entities, so that entities behave just like all other PHP objects, or do we want to prevent that for entities, since it's bad OOP practice in general for outside code to add arbitrary properties to objects, and potentially especially bad to do that on entities?If we want to treat entities as any other PHP object and allow it, then __get() *should* return by reference, but the issue summary says that that's confusing, but I'm not entirely clear why.
But, if we want to make the entity data model strict, to encourage/force good OOP practice at least with regards to entities, then we need to find every occurrence in HEAD that currently violates that and fix it. In some cases, that means turning something into a field. In other cases, it might mean storing temporary data (e.g., $entity->content) somewhere other than on $entity.
Comment #44
plachI am all for this second approach, but honestly I don't know whether it's still viable. Anyway, it's THE thing to do IMO, and what I've been aiming for since we started working on D8 entities.
Comment #45
fagoI agree that we should encourage good OOP practice and should not support writing internal field values, as the issue summary example shows.
However, supporting some temporary non-field data on the entity is ok imho - it's just what you would expect to work from a random object. I'd not say it's best practice to do it, but still it makes sense to me to let the object behave as normal as possible.
Agreed.
But problem is, that reference allows changing $this->field['foo'] also unless we add some useless intermediate "copy"? Or should we go with the middle-way would be to support non-fields but not by reference? That means you cannot do $entity->content[] = .. though, but at least writing temporary variables works.
I do not think this issue is critical though, so lowering to major.
Comment #46
BerdirAgree with not critical, thanks.
->content is (almost?) gone now with the entity build/view cache refactoring, but there are still a few things left that need the by-reference stuff.
Comment #47
jhedstromThis could really use an issue summary update.
Comment #51
alexpottDiscussed with @catch, @xjm, @effulgentsia, @amateescu, @Berdir, @plach, @tstoeckler. We agree that this is not a major bug because the issue summary doesn't really describe a bug. Yes the BC layer added for entities is complex and it would be great to remove it and some of the complexity and magic but at best this is a task. This issue should be re-scoped to deprecate it and remove core usage. Hopefully we can remove some of this in Drupal 9.
Comment #61
geek-merlinThis looks like a dup of the other nowadays.