You are here

function bulk_export_export in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 bulk_export/bulk_export.module \bulk_export_export()

FAPI gateway to the bulk exporter.

1 string reference to 'bulk_export_export'
bulk_export_menu in bulk_export/bulk_export.module
Implements hook_menu().

File

bulk_export/bulk_export.module, line 45
Perform bulk exports.

Code

function bulk_export_export() {
  ctools_include('export');
  $schemas = ctools_export_get_schemas(TRUE);
  $exportables = $export_tables = array();
  foreach ($schemas as $table => $schema) {
    if (!empty($schema['export']['list callback']) && function_exists($schema['export']['list callback'])) {
      $exportables[$table] = $schema['export']['list callback']();
    }
    else {
      $exportables[$table] = ctools_export_default_list($table, $schema);
    }
    natcasesort($exportables[$table]);
    $export_tables[$table] = $schema['module'];
  }
  if ($exportables) {
    ctools_include('form');
    $form_state = array(
      're_render' => FALSE,
      'no_redirect' => TRUE,
      'exportables' => $exportables,
      'export_tables' => $export_tables,
    );
    $output = ctools_build_form('bulk_export_export_form', $form_state);
    if (!$output) {
      drupal_set_title(t('Bulk export results'));
      $output = '';
      $module_code = '';
      $api_code = '';
      $dependencies = array();
      foreach ($form_state['code'] as $module => $api_info) {
        if ($module == 'general') {
          $module_code .= $api_info;
        }
        else {
          foreach ($api_info as $api => $info) {
            $api_code .= "  if (\$module == '{$module}' && \$api == '{$api}') {\n";
            $api_code .= "    return array('version' => {$info['version']});\n";
            $api_code .= "  }\n";
            $dependencies[$module] = TRUE;
            $file = $form_state['module'] . '.' . $api . '.inc';
            $code = "<?php\n";
            $code .= "/**\n";
            $code .= " * @file\n";
            $code .= " * Bulk export of {$api} objects generated by Bulk export module.\n";
            $code .= " */\n\n";
            $code .= $info['code'];
            $output .= drupal_get_form('ctools_export_form', $code, t('Place this in @file', array(
              '@file' => $file,
            )));
          }
        }
      }

      // Add hook_ctools_plugin_api at the top of the module code, if there is any.
      if ($api_code) {
        $api = "/**\n";
        $api .= " * Implements hook_ctools_plugin_api().\n";
        $api .= " */\n";
        $api .= "function {$form_state['module']}_ctools_plugin_api(\$module, \$api) {\n";
        $api .= $api_code;
        $api .= "}\n";
        $module_code = $api . $module_code;
      }
      if ($module_code) {
        $module = "<?php\n";
        $module .= "/**\n";
        $module .= " * @file\n";
        $module .= " * Bulk export of objects generated by Bulk export module.\n";
        $module .= " */\n\n";
        $module .= $module_code;
        $output = drupal_get_form('ctools_export_form', $module, t('Place this in @file', array(
          '@file' => $form_state['module'] . '.module',
        ))) . $output;
      }
      $info = strtr("name = @module export module\n", array(
        '@module' => $form_state['module'],
      ));
      $info .= strtr("description = Export objects from CTools\n", array(
        '@module' => $form_state['values']['name'],
      ));
      foreach ($dependencies as $module => $junk) {
        $info .= "dependencies[] = {$module}\n";
      }
      $info .= "package = Chaos tool suite\n";
      $info .= "core = 6.x\n";
      $output = drupal_get_form('ctools_export_form', $info, t('Place this in @file', array(
        '@file' => $form_state['module'] . '.info',
      ))) . $output;
    }
    return $output;
  }
  else {
    return t('There are no objects to be exported at this time.');
  }
}