You are here

function content_copy_record_macro in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 modules/content_copy/content_copy.module \content_copy_record_macro()
  2. 6 modules/content_copy/content_copy.module \content_copy_record_macro()
  3. 6.2 modules/content_copy/content_copy.module \content_copy_record_macro()

A handler that stores the form submissions into a $GLOBALS array

File

./content_copy.module, line 585
Adds capability to import/export cck field data definitions.

Code

function content_copy_record_macro($form_id, $edit, $form) {
  $subs = $GLOBALS['content_copy']['submissions'];

  // Get the form values and store them in a $GLOBALS['content_copy']['submissions'] array.
  // Update $GLOBALS['content_copy']['count'] with an approximation of the number of rows in this item.
  // Count is used to approximate necessary size of textarea in form.
  unset($edit['type_name'], $edit['submit'], $edit['delete'], $edit['form_id']);
  switch ($form_id) {
    case 'node_type_form':
      $subs['type'] = $edit;
      $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
      break;
    case 'fieldgroup_edit_group_form':
      $subs['groups'][] = $edit;
      $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
      break;
    default:
      if ($edit['field_widget_type']) {
        $tmp = explode('-', $edit['field_widget_type']);
        $field_name = $tmp[0];
      }
      else {
        $field_name = $edit['field_name'];
      }

      // The display settings are being fetched directly from the DB. During import,
      // we'll re-insert the data directly as well.
      //
      $query = 'SELECT display_settings FROM {node_field_instance} WHERE field_name = \'%s\'';
      $row_info = db_fetch_array(db_query($query, $field_name));

      // If an error occurs, notify the user.
      if ($db_err = db_error()) {
        drupal_set_message(t("An error occurred when exporting the 'display settings' data for the field %field_name.<br/>The db error is: '%db_err'.", array(
          '%field_name' => $field_name,
          '%db_err' => $db_err,
        )));
      }
      else {

        // The db fetch occurred successfully, unserialize the data blob and
        // insert it into a new "display_settings" field of the data.
        if ($display_settings = unserialize($row_info['display_settings'])) {
          $edit['display_settings'] = $display_settings;
        }
      }
      $subs['fields'][] = $edit;
      $GLOBALS['content_copy']['count'] += sizeof($edit) + 5;
      break;
  }
  $GLOBALS['content_copy']['submissions'] = $subs;
}