The darker side of Drupal; Field collections and revisioning/moderation

Field collections are awesome, we all know that. When it comes to revisioning it starts to turn sour, go deeper and include workflow moderation and it really turns dark.

Field collections by default don’t revision, so if you edited a node and saved it as draft the field collection value would be published. I was using this in combination with the Wokbench Moderation (a great module that you should check out if you haven't already). When I came across this it seemed to be a fairly known problem, however getting all the information together took a fair bit of time. Hopefully the below will save others time that I spent.

To Solve this:

If you load field colelctions in anything other than the node template file to get field collection fields use:

$field_collection = field_get_items('node', $node, 'field_collection_field', $node->language);

  if ($field_collection) { 
foreach ($field_collection as $collection) {  
$title = field_collection_field_get_entity($collection, 'field_title'); 

If you're using links in field collections you'll also need the latest version of the links module or database errors occur when you try to save the field.

Massive thanks to John Pitcarin for the above patches and information.