When a new field collection is created and attached to its host, it cannot be accessed via a EntityListWrapper until it have been saved.

This change coupled with #1587882: Allow getter callbaks to provide lists of entity objects allows for the EntityListWrapper to access a list with both ids and entities making it much easier to manage field collections before they are saved.

Also when you have multiple new field collections there is a bug in which the field language is returned as 0 unstead of (normally) und. This is fixed in #1587874: field_language() caching to strict when creating multiple new entity types with different bundles.

Files: 
CommentFileSizeAuthor
patch_commit_7703becd22b5.patch825 bytesgordon
PASSED: [[SimpleTest]]: [MySQL] 78 pass(es).
[ View ]

Comments

Status:Needs review» Needs work

current source tells us that this is fixed for single value fields but needs a fix in the wrapper for multiple valued ones.

Wrappers do not support multiple entity references being revisions or not yet saved entities.

did not check that though.
would be great to have.

<?php
/**
* Entity property info getter callback for the field collection items.
*
* Like entity_metadata_field_property_get(), but additionally supports getting
* not-yet saved collection items from @code $item['entity'] @endcode.
*/
function field_collection_field_property_get($entity, array $options, $name, $entity_type, $info) {
 
$field = field_info_field($name);
 
$langcode = field_language($entity_type, $entity, $name, isset($options['language']) ? $options['language']->language : NULL);
 
$values = array();
  if (isset(
$entity->{$name}[$langcode])) {
    foreach (
$entity->{$name}[$langcode] as $delta => $data) {
     
// Wrappers do not support multiple entity references being revisions or
      // not yet saved entities. In the case of a single reference we can return
      // the entity object though.
     
if ($field['cardinality'] == 1) {
       
$values[$delta] = field_collection_field_get_entity($data);
      }
      elseif (isset(
$data['value'])) {
       
$values[$delta] = $data['value'];
      }
    }
  }
 
// For an empty single-valued field, we have to return NULL.
 
return $field['cardinality'] == 1 ? ($values ? reset($values) : NULL) : $values;
}
?>

Status:Needs work» Needs review

patch_commit_7703becd22b5.patch queued for re-testing.