When working with field collections, entity makes them usable, however when dealing with newly attached field collections you are unable to access then via a EntityListWrapper as it is only expecting an id, and the is no way to pass the new entity object.

This makes a small change which allows the field collection module to return any field collections which have not yet been saved as a part of the list so they can be accessed via the EntityWrapper object.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, patch_commit_7e10c932c8a9.patch, failed testing.

gordon’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
1.42 KB

recreate the patch against 1.x-dev

fago’s picture

Title: Allow EntityListWrapper to handle a list of Entities and ids » Allow getter callbaks to provide lists of entity objects
Status: Needs review » Needs work
Issue tags: +Needs tests

This sounds like a good improvement, so let's do it. Maybe we could just assume we have a list of full objects if the first entry is a object ? Supporting mixed lists doesn't make much sense to me.

However, we should note this possibility at the data-type docs ( see hook_entity_property_info()). Then we should add a little code snippet to the tests making use of the functionality, as this is rather foundational it really shouldn't break.

+++ b/includes/entity.wrapper.inc
@@ -1011,6 +1012,13 @@ class EntityListWrapper extends EntityMetadataWrapper implements IteratorAggrega
+    return !($value instanceof Entity);

We cannot rely on entities being of class entity, actually most aren't.

RoSk0’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.04 KB
3.36 KB

Patch is based on @gordon idea because I think it's totally legit use case when first item in the list will be save object and second will be just added, not saved, but we still want to be able to work with it. I wasn't able to figure proper language to update documentation so help here will be appreciated. Patch also includes parent update for unsaved objects and ability to set unsaved object as list item because without this ability this issue in general will be useful only to field collection because it update parent entity directly, without using wrapper, in its FieldCollectionItemEntity::setHostEntity() method.

RoSk0’s picture

Attempt to update docs.

RoSk0’s picture

Gold’s picture

Status: Needs review » Reviewed & tested by the community

This is looking good to me. Tests are completing successfully.