function content_copy_export in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 5 content_copy.module \content_copy_export()
- 6 modules/content_copy/content_copy.module \content_copy_export()
- 6.2 modules/content_copy/content_copy.module \content_copy_export()
Process the export, get field admin forms for all requested fields and save the form values as formatted text.
1 call to content_copy_export()
- content_copy_export_form in modules/
content_copy/ content_copy.module - A form to export field definitions.
File
- modules/
content_copy/ content_copy.module, line 209 - Adds capability to import/export CCK field data definitions.
Code
function content_copy_export($form_values) {
// Set a global variable to tell when to intervene with form_alter().
$GLOBALS['content_copy']['status'] = 'export';
// Get the content type info by submitting the content type form.
$node_state = array(
'values' => array(
'type_name' => $form_values['type_name'],
),
);
module_load_include('inc', 'node', 'content_types');
drupal_execute('node_type_form', $node_state, node_get_types('type', $form_values['type_name']));
module_load_include('inc', 'content', 'includes/content.admin');
module_load_include('inc', 'content', 'includes/content.crud');
// Get an array of groups to export.
// Record a macro for each group by submitting the group edit form.
$groups = array();
if (!empty($form_values['groups']) && module_exists('fieldgroup')) {
$groups = array_filter($form_values['groups']);
foreach ($groups as $group) {
$group_state = array(
'values' => array(
'group_name' => $group,
),
);
drupal_execute('fieldgroup_group_edit_form', $group_state, $form_values['type_name'], $group, 'edit');
}
}
// Get an array of fields to export
// Record a macro for each field by submitting the field settings form.
// Omit fields from the export if their module is not currently installed
// otherwise the system will generate errors when the macro tries to execute their forms.
if (!empty($form_values['fields'])) {
$type = content_types($form_values['type_name']);
$fields = array_filter($form_values['fields']);
foreach ($fields as $field_name) {
$field = $type['fields'][$field_name];
$field_types = _content_field_types();
$field_module = $field_types[$field['type']]['module'];
$widget_types = _content_widget_types();
$widget_module = $widget_types[$field['widget']['type']]['module'];
if (!empty($field_module) && module_exists($field_module) && !empty($widget_module) && module_exists($widget_module)) {
$field_state = array(
'values' => content_field_instance_collapse($field),
);
$field_state['values']['op'] = t('Save field settings');
if (module_exists('fieldgroup')) {
// Avoid undefined index error by always creating this.
$field_state['values']['group'] = '';
$group_name = fieldgroup_get_group($form_values['type_name'], $field_name);
if (in_array($group_name, $groups)) {
$field_state['values']['group'] = $group_name;
}
}
drupal_execute('content_field_edit_form', $field_state, $form_values['type_name'], $field_name);
}
}
}
// Convert the macro array into formatted text.
$output = content_copy_get_macro();
// Add weights of non-CCK fields.
if ($extra = variable_get('content_extra_weights_' . $form_values['type_name'], array())) {
$output .= "\$content['extra'] = " . var_export((array) $extra, TRUE) . ";\n";
}
return $output;
}