diff -rupN field_file.inc field_file.inc --- field_file.inc 2009-03-03 13:56:31.000000000 +0100 +++ field_file.inc 2009-03-03 14:30:21.000000000 +0100 @@ -202,7 +202,7 @@ function field_file_save_file($filepath, */ function field_file_save($node, &$file) { // If this item is marked for deletion. - if (!empty($file['delete'])) { + if (!empty($file['delete']) || !empty($file['_remove'])) { // If we're creating a new revision, return an empty array so CCK will // remove the item. if (!empty($node->old_vid)) { diff -rupN filefield_field.inc filefield_field.inc --- filefield_field.inc 2009-03-03 13:56:31.000000000 +0100 +++ filefield_field.inc 2009-03-03 17:18:32.000000000 +0100 @@ -87,14 +87,13 @@ function filefield_field_load($node, $fi // Despite hook_content_is_empty(), CCK still doesn't filter out // empty items from $op = 'load', so we need to do that ourselves. if (empty($item['fid']) || !($file = field_file_load($item['fid']))) { - unset($items[$delta]); + $items[$delta] = NULL; } else { $item['data'] = unserialize($item['data']); $items[$delta] = array_merge($item, $file); } } - $items = array_values($items); // compact deltas return array($field['field_name'] => $items); } @@ -109,12 +108,10 @@ function filefield_field_update($node, $ $curfids = array(); foreach ($items as $delta => $item) { $items[$delta] = field_file_save($node, $item); - // Remove items from the array if they have been deleted. - if (empty($items[$delta])) unset($items[$delta]); - $curfids[] = $item['fid']; + if (!empty($items[$delta]['fid'])) { + $curfids[] = $item['fid']; + } } - $items = array_values($items); // compact deltas - // if this is a new node... there are no // old items to worry about. @@ -138,8 +135,9 @@ function filefield_field_delete_revision foreach ($items as $delta => $item) { // For hook_file_references, remember that this is being deleted. $item['field_name'] = $field['field_name']; - if (field_file_delete($item)) unset($items[$delta]); - $items = array_values($items); // compact deltas + if (field_file_delete($item)) { + $items[$delta] = NULL; + } } } @@ -156,7 +154,6 @@ function filefield_field_sanitize($node, foreach ($items as $delta => $item) { // Cleanup $items during node preview. if (empty($item['fid']) || !empty($item['delete'])) { - unset($items[$delta]); continue; } // Load the complete file if a filepath is not available. diff -rupN filefield.module filefield.module --- filefield.module 2009-03-03 13:56:31.000000000 +0100 +++ filefield.module 2009-03-03 21:34:48.000000000 +0100 @@ -480,18 +480,31 @@ function filefield_js($type_name, $field // when rendered once more further down. form_clean_id(NULL, TRUE); + // Try to obtain the group name the field is in. + $group_name = module_exists('fieldgroup') ? _fieldgroup_field_get_group($type_name, $field_name) : NULL; + // Ask CCK for the replacement form element. Going through CCK gets us // the benefit of nice stuff like '#required' merged in correctly. - module_load_include('inc', 'content', 'includes/content.node_form'); - $field_element = content_field_form($form, $built_form_state, $field, $delta); - $delta_element = $field_element[$field_name][0]; // there's only one element in there - - // Add the new element at the right place in the form. - if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) { - $form[$group_name][$field_name][$delta] = $delta_element; + if (!empty($group_name) && isset($built_form['#multigroups']) && isset($built_form['#multigroups'][$group_name][$field_name])) { + $multigroup = TRUE; + $groups = fieldgroup_groups($type_name); + $group = $groups[$group_name]; + $built_form_state['item_count'] = array($group_name => count($_POST[$group_name])); + content_multigroup_group_form($form, $built_form_state, $group, $delta); } else { - $form[$field_name][$delta] = $delta_element; + $multigroup = FALSE; + module_load_include('inc', 'content', 'includes/content.node_form'); + $field_element = content_field_form($form, $built_form_state, $field, $delta); + $delta_element = $field_element[$field_name][0]; // there's only one element in there + + // Add the new element at the right place in the form. + if (!empty($group_name)) { + $form[$group_name][$field_name][$delta] = $delta_element; + } + else { + $form[$field_name][$delta] = $delta_element; + } } // Render the form for output. @@ -502,13 +515,13 @@ function filefield_js($type_name, $field drupal_alter('form', $form, array(), 'filefield_js'); $form_state = array('submitted' => FALSE); $form = form_builder('filefield_js', $form, $built_form_state); - $field_form = empty($group_name) ? $form[$field_name] : $form[$group_name][$field_name]; + $field_form = empty($group_name) ? $form[$field_name][$delta] : ($multigroup ? $form[$group_name][$delta][$field_name] : $form[$group_name][$field_name][$delta]); // We add a div around the new content to tell AHAH to let this fade in. - $field_form[$delta]['#prefix'] = '
'; - $field_form[$delta]['#suffix'] = '
'; + $field_form['#prefix'] = '
'; + $field_form['#suffix'] = '
'; - $output = drupal_render($field_form[$delta]); + $output = drupal_render($field_form); // AHAH is not being nice to us and doesn't know the "other" button (that is, // either "Upload" or "Delete") yet. Which in turn causes it not to attach