You are here

function features_export_build_form_populate in Features 7

Same name and namespace in other branches
  1. 6 features.admin.inc \features_export_build_form_populate()

AJAX callback for features_export_form_build().

1 string reference to 'features_export_build_form_populate'
features_export_form in ./features.admin.inc
Form constructor for features export form.

File

./features.admin.inc, line 287
@todo.

Code

function features_export_build_form_populate($form, $form_state) {
  module_load_include('inc', 'features', 'features.export');
  features_include();
  $stub = array();
  $submitted = $form_state['values'];

  // Assemble the combined component list
  $components = array_keys(features_get_components());
  foreach ($components as $component) {

    // User-selected components take precedence.
    if (!empty($submitted['sources'][$component])) {

      // Validate and set the default value for each selected option. This
      foreach ($submitted['sources'][$component] as $key => $value) {
        if (isset($form['export']['sources'][$component]['#options'][$key])) {
          $form['export']['sources'][$component]['#default_value'][$key] = $value;
        }
      }
      $stub[$component] = features_dom_decode_options(array_filter($submitted['sources'][$component]));
    }
    else {
      if (!empty($form['export']['sources'][$component]) && !empty($form['#feature']->info['features'][$component])) {
        $stub[$component] = $form['#feature']->info['features'][$component];
      }
    }
  }

  // Assemble dependencies
  $dependencies = isset($submitted['sources']['dependencies']) ? $submitted['sources']['dependencies'] : array();

  // Generate populated feature
  $module_name = isset($form['#feature'], $form['#feature']->name) ? $form['#feature']->name : '';
  $export = features_populate($stub, $dependencies, $module_name);

  // Render component display
  $components_rendered = theme('features_components', array(
    'info' => $export,
    'sources' => $stub,
  ));
  $form['export']['features']['#markup'] = $components_rendered;

  // @TODO: Reimplement this for D7.
  // Re-cache form. This ensures that if the form fails to validate, selected
  // values are preserved for the user.
  // form_set_cache($submitted['form_build_id'], $form, $form_state);
  return $form['export']['features'];
}