content_copy_export_form($form_values = NULL)content_copy_export_form(&$form_state)A form to export field definitions.
contributions/cck/modules/content_copy/content_copy.module, line 70
<?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;
$exportable_fields = array();
$groups = array();
$type_name = isset($form_values['type_name']) ? $form_values['type_name'] : '';
if ($type_name) {
$type = content_types($type_name);
$exportable_fields = content_copy_fields($type_name);
if (module_exists('fieldgroup')) {
$groups = fieldgroup_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) && !($exportable_fields)) {
$step = 3;
}
$form['#step'] = $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 an existing content type or create a new content type that includes the selected fields.');
switch ($step) {
case 1: // Select a content type.
$types = content_copy_types();
$form['type_name'] = array(
'#title' => t('Types'),
'#type' => 'radios',
'#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,
);
$form += array(
'#fields' => $exportable_fields,
'#groups' => array_keys($groups),
);
$fields_options = $groups_options = array();
// Fields.
foreach ($exportable_fields as $field_name) {
$field = content_fields($field_name, $type_name);
$fields_options[$field_name] = '';
$weight = $field['widget']['weight'];
$form[$field_name] = array(
'human_name' => array('#value' => check_plain($field['widget']['label'])),
'field_name' => array('#value' => $field['field_name']),
'type' => array('#value' => $field['type']),
'weight' => array('#type' => 'value', '#value' => $weight),
'parent' => array('#type' => 'value', '#value' => ''),
'#row_type' => 'field',
);
}
$form['fields'] = array(
'#type' => 'checkboxes',
'#options' => $fields_options,
'#default_value' => array_keys($fields_options),
);
// Groups.
foreach ($groups as $name => $group) {
$groups_options[$name] = '';
$weight = $group['weight'];
$form[$name] = array(
'human_name' => array('#value' => check_plain($group['label'])),
'group_name' => array('#value' => $group['group_name']),
'weight' => array('#type' => 'value', '#value' => $weight),
'#row_type' => 'group',
);
foreach ($group['fields'] as $field_name => $field) {
// Do nothing for non-exportable (inactive) fields.
if (isset($form[$field_name])) {
$form[$field_name]['parent']['#value'] = $name;
}
}
}
if ($groups) {
$form['groups'] = array(
'#type' => 'checkboxes',
'#options' => $groups_options,
'#default_value' => array_keys($groups_options),
);
}
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;
}
?>