Skip to content

Instantly share code, notes, and snippets.

@deepakaryan1988
Created December 18, 2014 11:35
Show Gist options
  • Select an option

  • Save deepakaryan1988/49ac39842e30ad350713 to your computer and use it in GitHub Desktop.

Select an option

Save deepakaryan1988/49ac39842e30ad350713 to your computer and use it in GitHub Desktop.
update field collection without saving entity
http://alexrayu.com/blog/saveupdate-field-collection-without-nodesave
// Get field collection (supposedly containing one image with meta data)
$fc = entity_load('field_collection_item', array($fcid));
// If we were to have multi-value fc's, we weould have a cycle here in place of current()
$fc = current($fc);
// Get meta data. A custom function.
$meta = custom_get_meta_data($fc);
// Assign meta data
$fc->field_title[LANGUAGE_NONE][0]['value'] = $meta->title;
$fc->field_author_name[LANGUAGE_NONE][0]['value'] = $meta->author;
$fc->field_caption[LANGUAGE_NONE][0]['value'] = $meta->caption;
$fc->field_alt_text[LANGUAGE_NONE][0]['value'] = $meta->alt_text;
$fc->field_short_caption[LANGUAGE_NONE][0]['value'] = $meta->short_caption;
entity_save('field_collection_item', $fc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment