function field_collection_field_property_set in Field collection 7
Entity property info setter callback for the field collection items.
Like entity_metadata_field_property_set(), but additionally supports saving the revision id.
1 string reference to 'field_collection_field_property_set'
- 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 2062 - Module implementing field collection field type.
Code
function field_collection_field_property_set($entity, $name, $value, $langcode, $entity_type) {
$field = field_info_field($name);
$columns = array_keys($field['columns']);
$langcode = entity_metadata_field_get_language($entity_type, $entity, $field, $langcode);
$values = $field['cardinality'] == 1 ? array(
$value,
) : (array) $value;
$items = array();
foreach ($values as $delta => $value) {
if (isset($value)) {
if ($value instanceof FieldCollectionItemEntity) {
$items[$delta][$columns[0]] = $value->item_id;
$items[$delta][$columns[1]] = $value->revision_id;
}
elseif (is_array($value) && isset($value['value'], $value['revision_id'])) {
$items[$delta][$columns[0]] = $value['value'];
$items[$delta][$columns[1]] = $value['revision_id'];
}
else {
$item = field_collection_item_load($value);
$items[$delta][$columns[0]] = $item->item_id;
$items[$delta][$columns[1]] = $item->revision_id;
}
}
}
$entity->{$name}[$langcode] = $items;
// Empty the static field language cache, so the field system picks up any
// possible new languages.
drupal_static_reset('field_language');
}