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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2346433_entity_iterators-4.patch | 1.99 KB | yched |
| #1 | 2346433_entity_iterators-1-do-no-test.patch | 1.99 KB | yched |
| #1 | 2346433_entity_iterators-1.patch | 71.4 KB | yched |
Comments
Comment #1
yched commentedLet'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.
Comment #4
yched commentedLooks green. #2002138: Use an adapter for supporting typed data on ContentEntities got committed, so re-uploading patch with just the relevant changes.
Comment #5
fagoAs 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.
Comment #7
webchickCommitted 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.
Comment #8
tstoecklerYay, this was WTF for quite some time, awesome!