function content_copy_export_form in Content Construction Kit (CCK) 6
Same name and namespace in other branches
- 5 content_copy.module \content_copy_export_form()
- 6.3 modules/content_copy/content_copy.module \content_copy_export_form()
- 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 modules/
content_copy/ content_copy.module - Implementation of hook_menu().
File
- modules/
content_copy/ content_copy.module, line 58 - Adds capability to import/export CCK field data definitions.
Code
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.'),
);
// 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_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('Export'),
);
}
$form['step'] = array(
'#type' => 'value',
'#value' => $step,
);
return $form;
}