You are here

function custom_formatters_export_ui_export_form in Custom Formatters 7.2

Provide a form for displaying an export.

Parameters

array $form: The form api array.

array $form_state: The form state array.

object $item: The Custom formatter object.

string $title: The textarea field title.

Return value

mixed A form api array.

2 string references to 'custom_formatters_export_ui_export_form'
ctools_custom_formatters_init in includes/ctools.inc
Implements hook_custom_formatters_init().
custom_formatters_ui::export_page in plugins/export_ui/custom_formatters_ui.class.php
Page callback to display export information for an exportable item.

File

plugins/export_ui/custom_formatters.inc, line 455
CTools Export UI plugin for SexyBookmarks profiles.

Code

function custom_formatters_export_ui_export_form($form, &$form_state, $item, $title = '') {
  $form['mode'] = array(
    '#type' => 'select',
    '#title' => t('Mode'),
    '#options' => array(
      'default' => t('CTools exportable (default)'),
      'drupal' => t('Drupal API'),
    ),
    '#default_value' => 'default',
    '#ajax' => array(
      'callback' => 'custom_formatters_export_ui_export_form_js',
      'wrapper' => 'export-wrapper',
    ),
  );
  $form['export'] = array(
    '#type' => 'container',
    '#prefix' => '<div id="export-wrapper">',
    '#suffix' => '</div>',
  );
  $mode = isset($form_state['values']['mode']) ? $form_state['values']['mode'] : $form['mode']['#default_value'];
  switch ($mode) {
    case 'default':
      $code = ctools_export_crud_export('formatters', $item);
      break;
    case 'drupal':
      $engines = module_invoke_all('custom_formatters_engine_info');
      $engine = $item->mode;
      if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
        require_once $engines[$engine]['file'];
      }
      $module = isset($form_state['values']['module']) ? $form_state['values']['module'] : t('MYMODULE');
      $form['export']['module'] = array(
        '#type' => 'textfield',
        '#title' => t('Module name'),
        '#default_value' => $module,
        '#ajax' => array(
          'callback' => 'custom_formatters_export_ui_export_form_js',
          'wrapper' => 'export-wrapper',
        ),
      );
      $code = $engines[$engine]['callbacks']['export']($item, $module);
      break;
  }
  $lines = substr_count($code, "\n");
  $form['export']['code'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($title),
    '#value' => $code,
    '#rows' => $lines,
  );
  return $form;
}