You are here

function field_collection_field_property_get in Field collection 7

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

$item['entity'];

.

1 string reference to 'field_collection_field_property_get'
field_collection_entity_metadata_property_callback in ./field_collection.module
Callback for generating entity metadata property info for our field instances.

File

./field_collection.module, line 2035
Module implementing field collection field type.

Code

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;
}