Commit 75067000 authored by gilgabar's avatar gilgabar Committed by Joel Muzzerall
Browse files

Issue #1937866 by justanothermark, gilgabar, kriboogh: Entity metadata wrapper...

Issue #1937866 by justanothermark, gilgabar, kriboogh: Entity metadata wrapper set method does not support field collection revisions
parent 2c041381
......@@ -1406,6 +1406,7 @@ function field_collection_entity_metadata_property_callback(&$info, $entity_type
// Set the bundle as we know it is the name of the field.
$property['bundle'] = $field['field_name'];
$property['getter callback'] = 'field_collection_field_property_get';
$property['setter callback'] = 'field_collection_field_property_set';
}
/**
......@@ -1459,6 +1460,42 @@ function field_collection_field_property_get($entity, array $options, $name, $en
return $field['cardinality'] == 1 ? ($values ? reset($values) : NULL) : $values;
}
/**
* Entity property info setter callback for the field collection items.
*
* Like entity_metadata_field_property_set(), but additionally supports
* saving the revision id.
*/
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']) && isset($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');
}
/**
* Implements hook_devel_generate().
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment