You are here

function content_copy_record_macro in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 content_copy.module \content_copy_record_macro()
  2. 6.3 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

1 string reference to 'content_copy_record_macro'
content_copy_form_alter in modules/content_copy/content_copy.module
Implementation of hook_form_alter(). Intervene to run form through macro when doing export

File

modules/content_copy/content_copy.module, line 464
Adds capability to import/export CCK field data definitions.

Code

function content_copy_record_macro($form, &$form_state) {
  $edit = $form_state['values'];
  $subs = isset($GLOBALS['content_copy']['submissions']) ? $GLOBALS['content_copy']['submissions'] : array();

  // 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.
  $form_id = $form_state['values']['form_id'];
  if (isset($edit['type_name']) || isset($edit['submit']) || isset($edit['delete']) || isset($edit['form_id'])) {
    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 (isset($edit['field_widget_type'])) {
        $tmp = explode('-', $edit['field_widget_type']);
        $field_name = $tmp[0];
      }
      else {
        $field_name = isset($edit['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;
}