You are here

function values_export_values in Values 7

Same name and namespace in other branches
  1. 6 values.module \values_export_values()

Export a value list and display it in a form.

1 string reference to 'values_export_values'
values_menu in ./values.module
Implements hook_menu().

File

./values.module, line 445
API for managing reusable value sets.

Code

function values_export_values($form, &$form_state, $value_set) {
  if (!module_exists('ctools')) {
    return array(
      'message' => array(
        '#value' => t('For exporting capabilities, please install the !ctools module.', array(
          '!ctools' => l('Chaos tools suite', 'http://drupal.org/project/ctools'),
        )),
      ),
    );
  }
  drupal_set_title($value_set->title);

  // Ctools Export
  $code = values_export($value_set);
  $lines = substr_count($code, "\n");
  $form['export_ctools'] = array(
    '#title' => t('Export data'),
    '#type' => 'textarea',
    '#value' => $code,
    '#rows' => $lines,
    '#description' => t('Copy the export text and paste it into another value list using the import function.'),
  );

  // Flat List
  $code = '';
  foreach ($value_set->data as $value) {
    $code .= $value['key'] . '|' . $value['value'] . "\n";
  }
  $lines = count($value_set->data);
  $form['export_flat'] = array(
    '#title' => t('Flat Export List'),
    '#type' => 'textarea',
    '#value' => $code,
    '#rows' => $lines,
    '#description' => t('Flat list that emulates the CCK/Field module Allowed Values list style. Can also be used to import using the import function.'),
  );
  return $form;
}