Contributions API

Calling all Drupal developers!

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

Modules in 6

content_copy_export

Definition

content_copy_export($form_values)
contributions/cck/modules/content_copy/content_copy.module, line 160

Description

Process the export, get field admin forms for all requested fields and save the form values as formatted text.

Code

<?php
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']));

  // TODO : also export "extra" fields weights.
  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.
  return content_copy_get_macro();
}
?>