You are here

function ds_display_overview_form_submit in Display Suite 6.2

Same name and namespace in other branches
  1. 6.3 includes/ds.display.inc \ds_display_overview_form_submit()
  2. 6 includes/ds.display.inc \ds_display_overview_form_submit()

Save fields & plugins for a build mode.

File

includes/ds.display.inc, line 515
Display overview form.

Code

function ds_display_overview_form_submit($form, &$form_state) {
  $module = $form['#module'];
  $build_mode = $form['#build_mode'];
  $type = $form['#type_name'];
  $extra = $form['#extra'];

  // Fields.
  $fields = ds_get_fields($module, $type, $build_mode, $extra, TRUE, FALSE);
  if (!empty($fields)) {
    foreach ($fields as $key => $field) {
      $region = $form_state['values'][$key][$build_mode]['region'];

      // Do not store these settings.
      if ($region == 'disabled') {

        // Ditch this field, unless it has its storage in another module (ie CCK)
        if (!isset($field['storage'])) {
          unset($form_state['values'][$key]);
        }
        continue;
      }
      $display_settings[$build_mode]['fields'][$key]['region'] = $region;
      $display_settings[$build_mode]['fields'][$key]['weight'] = $form_state['values'][$key]['ds_weight'];
      $display_settings[$build_mode]['fields'][$key]['format'] = $form_state['values'][$key][$build_mode]['format'];
      if (!empty($form_state['values'][$key][$build_mode]['subgroup_format'])) {
        $display_settings[$build_mode]['fields'][$key]['subgroup_format'] = $form_state['values'][$key][$build_mode]['subgroup_format'];
      }
      $class = implode(' ', $form_state['values'][$key][$build_mode]['css-class']);
      $display_settings[$build_mode]['fields'][$key]['css-class'] = $class;

      // Label value.
      if (!empty($form_state['values'][$key][$build_mode]['label_value'])) {
        $display_settings[$build_mode]['fields'][$key]['label_value'] = $form_state['values'][$key][$build_mode]['label_value'];
      }
      $display_settings[$build_mode]['fields'][$key]['labelformat'] = $form_state['values'][$key][$build_mode]['label']['format'];

      // Parent.
      $field_id = $form_state['values'][$key][$build_mode]['field_id'];
      $parent_id = $form_state['values'][$key][$build_mode]['parent_id'];
      if (!empty($parent_id)) {
        $display_settings[$build_mode]['fields'][$key]['parent'] = $parent_id;
      }

      // Ditch this field, unless it has its storage in another module (ie CCK)
      if (!isset($field['storage'])) {
        unset($form_state['values'][$key]);
      }
    }
  }

  // Plugins.
  if ($form['#plugins'] == TRUE) {
    ds_plugins_display_submit($form, $form_state, $display_settings);
  }

  // Status.
  $status = $form['#status'] == DS_SETTINGS_DEFAULT ? DS_SETTINGS_OVERRIDDEN : $form['#status'];
  $display_settings[$build_mode]['status'] = $status;

  // Sync / copy tab.
  ds_sync_copy_form_submit($form, $form_state, $display_settings);

  // Regions styles.
  $region_styles = array();
  foreach ($form['#regions'] as $region_key => $region_name) {
    if ($region_key != 'disabled') {
      $region_styles[$region_key] = implode(' ', $form_state['values']['region_styles_' . $region_key]);
    }
  }
  $display_settings[$build_mode]['region_styles'] = $region_styles;

  // Remove old settings.
  db_query("DELETE FROM {ds_settings} WHERE build_mode = '%s' AND module = '%s' AND type = '%s'", $build_mode, $module, $type);

  // Save new settings.
  $record = new stdClass();
  $record->module = $module;
  $record->type = $type;
  $record->build_mode = $build_mode;
  $record->settings = serialize($display_settings[$build_mode]);
  drupal_write_record('ds_settings', $record);

  // Check if we need to copy or sync.
  unset($display_settings[$build_mode]);
  if (!empty($display_settings)) {
    foreach ($display_settings as $sync_build_mode => $values) {

      // Remove old settings for this sync/copy build mode.
      db_query("DELETE FROM {ds_settings} WHERE build_mode = '%s' AND module = '%s' AND type = '%s'", $sync_build_mode, $module, $type);

      // Save new sync/copy settings.
      $record = new stdClass();
      $record->module = $module;
      $record->type = $type;
      $record->build_mode = $sync_build_mode;
      $record->settings = serialize($values);
      drupal_write_record('ds_settings', $record);
    }
  }

  // Confirmation message.
  drupal_set_message(t('Your settings have been saved.'));
}