After #2002138: Use an adapter for supporting typed data on ContentEntities, there are 3 ways to iterate on the fields of an entity:
- foreach ($entity as $field_name => $items)
- foreach ($entity->getFields() as $field_name => $items)
- foreach ($entity->getFieldDefinitions() as $field_name => $definition)

The 1st two are equivalent ($entity->getIterator() relies on $entity->getFields()), and skip computed fields. You need to use $entity->getFields(TRUE) if you want computed fields as well, which is inaccessible to the 1st way.
The 3rd one iterates on all fields, including computed fields.

We should make those three iterators equivalent - meaning, getFields($include_computed) should be TRUE by default instead of FALSE.

Comments

yched’s picture

Status: Active » Needs review
Issue tags: +Entity Field API
StatusFileSize
new71.4 KB
new1.99 KB

Let's see what breaks.

Patch for testbot rolled on top of #2002138: Use an adapter for supporting typed data on ContentEntities. Actual changes are in the do-not-test patch.

Status: Needs review » Needs work

The last submitted patch, 1: 2346433_entity_iterators-1-do-no-test.patch, failed testing.

Status: Needs work » Needs review
yched’s picture

StatusFileSize
new1.99 KB

Looks green. #2002138: Use an adapter for supporting typed data on ContentEntities got committed, so re-uploading patch with just the relevant changes.

fago’s picture

Status: Needs review » Reviewed & tested by the community

As discussed, it makes a lot of sense to make it consistently default to include computed fields for all iteration variants. RTBC assuming it's still green.

  • webchick committed 0d9e300 on 8.0.x
    Issue #2346433 by yched: Fixed  iterators omit computed fields by...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

effulgentsia also looked this over and wondered if we need a follow-up to do the same thing for properties.

tstoeckler’s picture

Yay, this was WTF for quite some time, awesome!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.