You are here

function cmis_sync_admin_form_submit in CMIS API 6.2

Implementation of hook_form_submit()

_state

@todo Add proper validation, optimization and ux

Parameters

$form:

File

cmis_sync/cmis_sync.admin.inc, line 227

Code

function cmis_sync_admin_form_submit($form, &$form_state) {
  $type_name = $form_state['values']['cmis_sync_drupal_type'];
  $cmis_sync_enabled = $form_state['values']['cmis_sync_enabled'];
  $cmis_sync_map = variable_get('cmis_sync_map', array());

  // CMIS sync enabled for this type ?
  $type_map =& $cmis_sync_map[$type_name];
  $type_map['enabled'] = $cmis_sync_enabled;
  $type_map['cmis_type'] = $form_state['values']['cmis_sync_cmis_type'];
  $type_map['cmis_root'] = $form_state['values']['cmis_sync_folder'];

  // Drupal node field that will be used to handle CMIS content
  if ($form_state['values']['cmis_sync_content'] != 'not_set') {
    $type_map['content_field'] = $form_state['values']['cmis_sync_content'];
  }
  else {
    unset($type_map['content_field']);
  }

  // Advanced sync options
  $type_map['full_sync_next_cron'] = $form_state['values']['cmis_sync_full_sync_next_cron'];
  $type_map['subfolders'] = $form_state['values']['cmis_sync_subfolders'];
  $type_map['deletes'] = $form_state['values']['cmis_sync_deletes'];
  if ($form_state['values']['cmis_sync_cmis_type'] && $form_state['values']['cmis_fields_map']) {

    // Cleaning up field map
    $type_map['fields'] = array();

    // Rebuilding the sync field map
    foreach ($form_state['values']['cmis_fields_map'] as $field => $field_map) {
      if ($field_map['rule_enabled'] == 1) {
        $type_map['fields'][] = array(
          'drupal' => $field_map['drupal_field'],
          'cmis' => $field_map['cmis_field'],
          'cmis to drupal' => (bool) $field_map['cmis_to_drupal'],
          'drupal to cmis' => (bool) $field_map['drupal_to_cmis'],
        );
      }
    }
  }

  // Saving sync field map
  variable_set('cmis_sync_map', $cmis_sync_map);
  drupal_set_message(t('Settings saved'));
}