You are here

function content_copy_export_form in Content Construction Kit (CCK) 5

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

A form to export field definitions.

1 string reference to 'content_copy_export_form'
content_copy_menu in ./content_copy.module
Implementation of hook_menu().

File

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

Code

function content_copy_export_form($form_values = NULL) {
  include_once './' . drupal_get_path('module', 'content') . '/content_admin.inc';
  include_once './' . drupal_get_path('module', 'content') . '/content_crud.inc';
  include_once './' . drupal_get_path('module', 'node') . '/content_types.inc';
  $step = intval($form_values['step'] + 1);
  $type_name = $form_values['type_name'];
  $types = content_copy_types();
  $fields = content_copy_fields($type_name);
  if (module_exists('fieldgroup')) {
    $groups = content_copy_groups($type_name);
  }

  // If a content type has been selected and there are no fields or groups to select,
  // jump straight to export.
  if ($step == 2 && !$groups && !$fields) {
    $step = 3;
  }
  $form['step'] = array(
    '#type' => 'hidden',
    '#value' => $step,
  );
  $form['#prefix'] = t('This form will process a content type and one or more fields from that type and export the settings. The export created by this process can be copied and pasted as an import into the current or any other database. The import will add the fields to into an existing content type or create a new content type that includes the selected fields.');
  $form['#multistep'] = TRUE;
  $form['#redirect'] = FALSE;
  switch ($step) {
    case 1:

      // Select a content type.
      $form['type_name'] = array(
        '#title' => t('Types'),
        '#type' => 'radios',
        '#multiple' => FALSE,
        '#options' => $types,
        '#description' => t('Select the content type to export.'),
      );

      // For some reason using #default_value in step 2 won't initialize
      // all fields as checked, but setting a hidden value in step 1 will do it.
      if (module_exists('fieldgroup')) {
        $form['groups'] = array(
          '#type' => 'hidden',
          '#value' => serialize(array_keys(content_copy_groups())),
        );
      }
      $form['fields'] = array(
        '#type' => 'hidden',
        '#value' => serialize(array_keys(content_fields())),
      );
      break;
    case 2:

      // Select groups and fields.
      $form['type_name'] = array(
        '#type' => 'hidden',
        '#value' => $type_name,
      );
      if (module_exists('fieldgroup') && !empty($groups)) {
        $form['groups'] = array(
          '#title' => t('Groups'),
          '#type' => 'checkboxes',
          '#multiple' => TRUE,
          '#options' => $groups,
          '#description' => t('Select the group definitions to export from %type.', array(
            '%type' => node_get_types('name', $type_name),
          )),
        );
      }
      $form['fields'] = array(
        '#title' => t('Fields'),
        '#type' => 'checkboxes',
        '#multiple' => TRUE,
        '#options' => $fields,
        '#description' => t('Select the field definitions to export from %type.', array(
          '%type' => node_get_types('name', $type_name),
        )),
      );
      break;
    case 3:

      // Display the export macro.
      $GLOBALS['content_copy']['count'] = 0;
      $form['export'] = array(
        '#title' => t('Export data'),
        '#type' => 'textarea',
        '#cols' => 60,
        '#value' => content_copy_export($form_id, $form_values),
        '#rows' => max(40, $GLOBALS['content_copy']['count']),
        '#description' => t('Copy the export text and paste it into another content type using the import function.'),
      );
      break;
  }
  if ($step < 3) {

    // Omit submit button on the textarea block to display the export data.
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
  }
  return $form;
}