You are here

function features_export_form in Features 6

Same name and namespace in other branches
  1. 7.2 features.admin.inc \features_export_form()
  2. 7 features.admin.inc \features_export_form()

Form callback for features export form. Acts as a router based on the form_state.

1 string reference to 'features_export_form'
features_menu in ./features.module
Implementation of hook_menu().

File

./features.admin.inc, line 6

Code

function features_export_form($form_state, $feature = NULL) {
  module_load_include('inc', 'features', 'features.export');
  features_include();
  $form = array(
    '#attributes' => array(
      'class' => 'features-export-form',
    ),
    '#feature' => isset($feature) ? $feature : NULL,
  );
  $form['info'] = array(
    '#type' => 'fieldset',
    '#tree' => FALSE,
  );
  $form['info']['name'] = array(
    '#title' => t('Name'),
    '#description' => t('Example: Image gallery'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => !empty($feature->info['name']) ? $feature->info['name'] : '',
    '#attributes' => array(
      'class' => 'feature-name',
    ),
  );
  $form['info']['module_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Machine-readable name'),
    '#description' => t('Example: image_gallery') . '<br/>' . t('May only contain lowercase letters, numbers and underscores. <strong>Try to avoid conflicts with the names of existing Drupal projects.</strong>'),
    '#required' => TRUE,
    '#default_value' => !empty($feature->name) ? $feature->name : '',
    '#attributes' => array(
      'class' => 'feature-module-name',
    ),
    '#element_validate' => array(
      'features_export_form_validate_field',
    ),
  );

  // If recreating this feature, disable machine name field and blank out
  // js-attachment classes to ensure the machine name cannot be changed.
  if (isset($feature)) {
    $form['info']['module_name']['#value'] = $feature->name;
    $form['info']['module_name']['#disabled'] = TRUE;
    $form['info']['name']['#attributes'] = array();
  }
  $form['info']['description'] = array(
    '#title' => t('Description'),
    '#description' => t('Provide a short description of what users should expect when they enable your feature.'),
    '#type' => 'textfield',
    '#required' => TRUE,
    '#default_value' => !empty($feature->info['description']) ? $feature->info['description'] : '',
  );
  $form['info']['version'] = array(
    '#title' => t('Version'),
    '#description' => t('Examples: 6.x-1.0, 6.x-1.0-beta1'),
    '#type' => 'textfield',
    '#required' => FALSE,
    '#default_value' => !empty($feature->info['version']) ? $feature->info['version'] : '',
    '#size' => 30,
    '#element_validate' => array(
      'features_export_form_validate_field',
    ),
  );
  $form['info']['project_status_url'] = array(
    '#title' => t('URL of update XML'),
    '#description' => t('Example: http://mywebsite.com/fserver'),
    '#type' => 'textfield',
    '#required' => FALSE,
    '#default_value' => !empty($feature->info['project status url']) ? $feature->info['project status url'] : '',
    '#size' => 30,
    '#element_validate' => array(
      'features_export_form_validate_field',
    ),
  );

  // User-selected feature source components.
  $components = features_get_components();
  uasort($components, 'features_compare_component_name');
  $form['export'] = array(
    '#type' => 'fieldset',
    '#tree' => FALSE,
    '#theme' => 'features_form_export',
  );
  $form['export']['components'] = array(
    '#title' => t('Edit components'),
    '#type' => 'select',
    '#options' => array(
      '------',
    ),
    '#attributes' => array(
      'class' => 'features-select-components',
    ),
  );
  $form['export']['sources'] = array(
    '#tree' => TRUE,
    '#theme' => 'features_form_components',
  );
  foreach ($components as $component => $component_info) {
    $options = features_invoke($component, 'features_export_options');
    if ($component === 'dependencies') {
      $default_value = !empty($feature->info['dependencies']) ? $feature->info['dependencies'] : array();
    }
    else {
      $default_value = !empty($feature->info['features'][$component]) ? $feature->info['features'][$component] : array();
    }
    if ($options) {

      // Find all default components that are not provided by this feature and
      // strip them out of the possible options.
      if ($map = features_get_default_map($component)) {
        foreach ($map as $k => $v) {
          if (isset($options[$k]) && (!isset($feature->name) || $v !== $feature->name)) {
            unset($options[$k]);
          }
        }
      }

      // Ensure all options are stripped of potentially bad values.
      foreach ($options as $k => $v) {
        $options[$k] = check_plain($v);
      }
      $label = isset($component_info['name']) ? $component_info['name'] . ": " . $component : $component;
      $form['export']['components']['#options'][$component] = $label;
      if (!empty($options)) {
        $form['export']['sources'][$component] = array(
          '#type' => 'checkboxes',
          '#options' => features_dom_encode_options($options),
          '#title' => $component,
          '#default_value' => features_dom_encode_options($default_value, FALSE),
          '#ahah' => array(
            'path' => 'admin/build/features/export/populate',
            'wrapper' => 'features-export-populated',
          ),
        );
      }
      else {
        $form['export']['sources'][$component] = array(
          '#type' => 'item',
          '#title' => $component,
          '#value' => t('All components of this type are exported by other features or modules.'),
        );
      }
    }
  }
  $form['export']['features'] = array(
    '#tree' => TRUE,
    '#type' => 'markup',
    '#prefix' => "<div id='features-export-populated'>",
    '#suffix' => "</div>",
    '#value' => !empty($feature->info) ? theme('features_components', $feature->info, $feature->info['features']) : "<div class='placeholder'></div>",
  );
  $form['buttons'] = array(
    '#theme' => 'features_form_buttons',
    '#tree' => FALSE,
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Download feature'),
    '#weight' => 10,
    '#submit' => array(
      'features_export_build_form_submit',
    ),
  );
  return $form;
}