Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

content_copy_export_form

Definition

content_copy_export_form(&$form_state)
contributions/cck/modules/content_copy/content_copy.module, line 58

Description

A form to export field definitions.

Code

<?php
function content_copy_export_form(&$form_state) {
  include_once('./'. drupal_get_path('module', 'content') .'/includes/content.admin.inc');
  include_once('./'. drupal_get_path('module', 'node') .'/content_types.inc');

  $form_values = isset($form_state['values']) ? $form_state['values'] : array();
  $step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1;

  $type_name = isset($form_values['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['#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.');

  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.'),
      );
      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_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.'),
      );
      // The calls to drupal_execute('content_field_edit_form') in
      // content_copy_export() affect the page title,
      drupal_set_title(t('Content types'));
      break;
  }

  if ($step < 3) {  // Omit submit button on the textarea block to display the export data.
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Export'),
    );
  }

  $form['step'] = array(
    '#type' => 'value',
    '#value' => $step,
  );

  return $form;
}
?>