1 config.admin.inc config_export_single_form(array $form, array &$form_state, $config_group = NULL, $config_name = NULL)

Form callback; Builds the form for exporting a single configuration file.

File

core/modules/config/config.admin.inc, line 273
Administrative pages and callbacks for the Configuration management module.

Code

function config_export_single_form(array $form, array &$form_state, $config_group = NULL, $config_name = NULL) {
  $form_state['config_groups'] = config_get_prefix_groups();
  $form['#attached']['css'][] = backdrop_get_path('module', 'config') . '/css/config.admin.css';

  $form['description'] = array(
    '#markup' => '<p>' . t('This form may be used to export a single configuration so that it may be imported on a different site. Select a configuration group and name to generate configuration for copy/paste.') . '</p>',
  );

  // Pull config group from URL if not provided.
  if (empty($config_group) && isset($_GET['group'])) {
    $config_group = $_GET['group'];
  }

  $group_options = backdrop_map_assoc(array_keys($form_state['config_groups']));
  natsort($group_options);
  $form['config_group'] = array(
    '#title' => t('Configuration group'),
    '#type' => 'select',
    '#options' => $group_options,
    '#default_value' => $config_group,
    '#required' => TRUE,
    '#ajax' => array(
      // The content wrapper to replace is specified in this AJAX callback.
      'callback' => 'config_export_single_form_update_type',
    ),
  );

  // Pull config name from URL if not provided.
  if (empty($config_name) && isset($_GET['name'])) {
    $config_name = $_GET['name'];
  }

  $default_type = isset($form_state['values']['config_group']) ? $form_state['values']['config_group'] : $config_group;
  $config_names = array();
  if ($default_type) {
    $config_names = $form_state['config_groups'][$default_type];
    natsort($config_names);
  }
  $form['config_name'] = array(
    '#title' => t('Configuration name'),
    '#type' => 'select',
    '#options' => $config_names,
    '#default_value' => $config_name,
    '#required' => TRUE,
    '#prefix' => '<div id="edit-config-type-wrapper">',
    '#suffix' => '</div>',
    '#ajax' => array(
      'callback' => 'config_export_single_form_update_export',
      'wrapper' => 'edit-export-wrapper',
    ),
  );

  $form['export'] = array(
    '#title' => t('Exported configuration'),
    '#type' => 'textarea',
    '#rows' => 12,
    '#prefix' => '<div id="edit-export-wrapper">',
    '#suffix' => '</div>',
  );

  if ($config_group || $config_name) {
    if (empty($form_state['values'])) {
      $form_state['values'] = array();
    }
    $form_state['values'] += array(
      'config_group' => $config_group,
      'config_name' => $config_name,
    );
    $form['export'] = config_export_single_form_update_export($form, $form_state);
  }

  return $form;
}