--- content_copy.module.original 2009-11-27 18:39:46.000000000 -0500 +++ content_copy.module 2009-11-27 18:32:47.000000000 -0500 @@ -464,8 +464,10 @@ $field['type_name'] = $type_name; if (!empty($field['field_name']) && isset($content_info['content types'][$type_name]['fields'][$field_name])) { - drupal_set_message(t('The imported field %field_label (%field_name) was not added to %type because that field already exists in %type.', array( - '%field_label' => $field['label'], '%field_name' => $field_name, '%type' => $type_label))); + $field = content_field_instance_update($field, FALSE); + $rebuild = TRUE; + drupal_set_message(t('The field %field_label (%field_name) was updated for the content type %type.', array( + '%field_label' => $field['widget']['label'], '%field_name' => $field_name, '%type' => $type_label))); } else { $field = content_field_instance_create($field, FALSE); @@ -474,6 +476,11 @@ '%field_label' => $field['widget']['label'], '%field_name' => $field_name, '%type' => $type_label))); } + // remove the field just processed from the content_info + // this way what it is left in the content_info are fields + // that have to be removed because no longer present in the content type + unset($content_info['content types'][$type_name]['fields'][$field_name]); + // Fieldgroup module erases all group related data when a module that // provides a content type is disabled, but CCK does not remove the fields. // In this case, we should ensure group data related to fields is properly @@ -484,6 +491,17 @@ } } + // if we are updating an existing content type + if ($form_values['type_name'] != '') { + // let's look for fields to be deleted + foreach ($content_info['content types'][$type_name]['fields'] as $field) { + content_field_instance_delete($field['field_name'], $type_name, FALSE); + drupal_set_message(t('The field %field_label (%field_name) was removed from the content type %type.', array( + '%field_label' => $field['widget']['label'], '%field_name' => $field_name, '%type' => $type_label))); + $rebuild = TRUE; + } + } + // Clear caches and rebuild menu only if any field has been created. if ($rebuild) { content_clear_type_cache(TRUE);