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 276
Admin page 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(
    '#type' => 'help',
    '#markup' => 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.'),
  );

  // 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) {
    // Prevent fatal errors if the key is not available in the select list.
    if (isset($form_state['config_groups'][$default_type])) {
      $config_names = $form_state['config_groups'][$default_type];
      natsort($config_names);
    }
    else {
      $config_names = array();
      backdrop_set_message(t('Configuration group %type not available.', array(
        '%type' => $default_type,
      )), 'warning');
    }
  }
  $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;
}