You are here

function cer_settings_form_submit in Corresponding Entity References 7

Same name and namespace in other branches
  1. 7.2 cer.admin.inc \cer_settings_form_submit()

Submit function for settings form.

File

./cer.admin.inc, line 92
Admin functionality, separated for performance purposes.

Code

function cer_settings_form_submit($form, $form_values) {
  ctools_include('export');
  $query_values = array();
  $mapping = unserialize($form_values['values']['mapping']);
  foreach ($form_values['values'] as $key => $value) {
    $keys = explode('_', $key);
    if ($keys[0] == 'enabled') {
      $query_values[$mapping[$keys[1]]] = $value;
    }
  }

  // load all existing presets
  $presets = ctools_export_crud_load_all('cer');
  foreach ($query_values as $key => $value) {

    // get preset object (create new one if it doesn't exist already).
    $preset = empty($presets[$key]) ? ctools_export_crud_new('cer') : $presets[$key];

    // set and save value
    if (empty($preset->entity_types_content_fields)) {
      $preset->entity_types_content_fields = $key;
    }
    $preset->enabled = $value;
    ctools_export_crud_save('cer', $preset);

    // remove from list of presets, so we know which ones are still used
    if (isset($presets[$key])) {
      unset($presets[$key]);
    }
  }

  // delete old presets
  foreach ($presets as $preset) {

    //ctools_export_crud_delete($preset);
  }
  drupal_set_message(t('The configuration has been saved'));
}