Hi,
When you use the publish in the Actions widget, rather than saving a node, field collections are broken unless you save a node as published, using the publish widget results in an "Unconnected field collection item" which you cannot edit as it has lost its association with the node.

Comments

StephenRobinson created an issue.

StephenRobinson’s picture

field_collection_item does not have the correct revision added unless you save the node.

StephenRobinson’s picture

Great having a conversation with myself here.....but I have found a way of correcting this:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if($form_id=='workbench_moderation_moderate_form'){
    $form['#submit'][]='_fix_field_collections';
  }
}
function _fix_field_collections(&$form, &$form_state){
  $fields = array_keys(db_query("SELECT DISTINCT field_name FROM field_collection_item ORDER BY field_name ASC")->fetchAllAssoc('field_name'));
  foreach($fields as $field){
    if(isset($form['node']['#value']->$field)){
      if(is_array($form['node']['#value']->$field)){
        $fieldobj=$form['node']['#value']->$field;
        if(is_array($fieldobj)){
          if(!empty($fieldobj['und'])){
            foreach($fieldobj['und'] as $fc){
              db_update('field_collection_item')->fields(array('revision_id' => $fc['revision_id']))->condition('item_id', $fc['value'], '=')->condition('field_name', $field, '=')->execute();
            }
          }
        }
      }
    }
  }
}
StephenRobinson’s picture

deleted

StephenRobinson’s picture

I have a fix to update bad entries:

    $fields = array_keys(db_query("SELECT DISTINCT field_name FROM field_collection_item ORDER BY field_name ASC")->fetchAllAssoc('field_name'));
    foreach($fields as $field){
      $results=db_query("SELECT field_collection_item.item_id, field_collection_item.revision_id as fcvid, field_collection_item.field_name, field_data_".$field.".".$field."_revision_id as fvid FROM field_collection_item INNER JOIN field_data_".$field." ON field_collection_item.item_id=field_data_".$field.".".$field."_value
");
      foreach($results as $result){
        if( $result->fcvid != $result->fvid ){
          db_update('field_collection_item')->fields(array('revision_id ' => $result->fvid))->condition('item_id', $result->item_id, '=')->execute();
        }
      }
    }