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:

  1. How does the system determine what properties an entity object has? Like, $node.
  2. How do those properties get populated?
  3. Given the amount of magic, any caveats retrieving those properties
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

msonnabaum’s picture

Documentation is not the answer here.

msonnabaum’s picture

Issue summary: View changes

Updated issue summary.

chx’s picture

Issue summary: View changes

Updated issue summary.

fago’s picture

Title: Mayday: the entity-field API is ungrokable » Mayday: the entity-field BC-layer is ungrokable

You 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.

fago’s picture

berdir suggested to add the new variant here, so I do:

$entities[$row->entity_id]->getTranslation($row->langcode)->{$field_name}[] = $item;

or just

$entities[$row->entity_id]->{$field_name}[] = $item;

if the langcode is default language anyway.

catch’s picture

Status: Active » Postponed (maintainer needs more info)

Isn't this just "remove the backwards compatibility layer" if so that's #1818580: [Meta] Convert all entity types to the new Entity Field API.

chx’s picture

Title: Mayday: the entity-field BC-layer is ungrokable » Mayday: the entity-field system is ungrokable
Status: Postponed (maintainer needs more info) » Active

Just because the BC layer makes it harder it doesn't mean the NG system relying on &__get will go away?

fago’s picture

>NG system relying on &__get

The NG system does not rely on that?

dcam’s picture

http://drupal.org/node/1427826 contains instructions for updating the issue summary with the summary template.

catch’s picture

Status: Active » Postponed (maintainer needs more info)

Back to needs more info. There's still nothing specific here that's not due to the backwards compatibility layer.

catch’s picture

Issue summary: View changes

Updated issue summary.

effulgentsia’s picture

Issue summary: View changes
Issue tags: +Entity Field API

Tagging to get this to show up in all the relevant lists.

chx’s picture

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

effulgentsia’s picture

Title: Mayday: the entity-field system is ungrokable » Fix ContentEntityBase::__get() to not return by reference
Status: Postponed (maintainer needs more info) » Needs review
FileSize
1.04 KB

Sure. Now that we don't need it for BC support, let's resolve that @todo.

Status: Needs review » Needs work

The last submitted patch, 11: entity_get_not_by_ref-1977266-11.patch, failed testing.

Berdir’s picture

No, that's not possible as long as we have code the one mentioned in the @todo, I left that there for a reason :)

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
3.75 KB

Well, let's at least see how far the rabbit hole goes.

Berdir’s picture

Sure :)

The translation part is handled in #1916790: Convert translation metadata into regular entity fields, no idea what to do with ->content.

Status: Needs review » Needs work

The last submitted patch, 14: entity_get_not_by_ref-1977266-14.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
5.62 KB
effulgentsia’s picture

Expanding the scope of this patch to track down other cases of non-field properties.

Status: Needs review » Needs work

The last submitted patch, 18: entity_get_not_by_ref-1977266-18.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
13.7 KB

Status: Needs review » Needs work

The last submitted patch, 20: entity_get_not_by_ref-1977266-20.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
13.9 KB

Status: Needs review » Needs work

The last submitted patch, 22: entity_get_not_by_ref-1977266-22.patch, failed testing.

effulgentsia’s picture

Status: Needs work » Needs review
FileSize
14.31 KB

Status: Needs review » Needs work

The last submitted patch, 24: entity_get_not_by_ref-1977266-24.patch, failed testing.

The last submitted patch, 24: entity_get_not_by_ref-1977266-24.patch, failed testing.

effulgentsia’s picture

Grrrr. I give up. Anyone have an idea how to reproduce bot's installation failure?

haydeniv’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: entity_get_not_by_ref-1977266-24.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review
FileSize
13.75 KB

I wasn't able to reproduce the install fail but here is a reroll for a conflict with #2028037: Expand FeedInterface with methods.

star-szr’s picture

FileSize
14.32 KB
587 bytes

Missed this added property, going to cancel the last one.

The last submitted patch, 30: 1977266-30.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 31: 1977266-31.patch, failed testing.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Needs work » Needs review
FileSize
15.58 KB

Rerolled. No interdiff possible.

Status: Needs review » Needs work

The last submitted patch, 34: content-entity-1977266-34.patch, failed testing.

Berdir’s picture

#18:

Expanding the scope of this patch to track down other cases of non-field properties.

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.

tim.plunkett’s picture

Well 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...

Berdir’s picture

So 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().

Berdir’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 34: content-entity-1977266-34.patch, failed testing.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Nevermind then.

Berdir’s picture

Actually, 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?

effulgentsia’s picture

So, 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.

plach’s picture

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.

I 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.

fago’s picture

Priority: Critical » Major

I 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.

I'd rather have support for non-fields than weird public properties like the recent pages have.

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.

Berdir’s picture

Agree 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.

jhedstrom’s picture

This could really use an issue summary update.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Category: Bug report » Task
Priority: Major » Normal

Discussed 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

geek-merlin’s picture

This looks like a dup of the other nowadays.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.