You are here

function cpn_settings_submit in Code per Node 6

Same name and namespace in other branches
  1. 7 cpn.admin.inc \cpn_settings_submit()

FormAPI submit callback for the CPN form.

1 string reference to 'cpn_settings_submit'
cpn_settings in ./cpn.admin.inc
Settings form.

File

./cpn.admin.inc, line 136
Manage the CPN settings page.

Code

function cpn_settings_submit($form, &$form_state) {

  // Trim slashes from the path.
  $form_state['values']['cpn_path'] = trim($form_state['values']['cpn_path'], '/');

  // If the path changed, notify that the folder must be moved.
  $old_path = variable_get('cpn_path', 'cpn');
  if ($form_state['values']['cpn_path'] != $old_path && file_exists(file_directory_path() . '/' . $old_path)) {
    drupal_set_message(t('The file storage path has changed; thus, the contents of %old_path must manually be moved to %new_path.', array(
      '%old_path' => file_directory_path() . '/' . $old_path,
      '%new_path' => file_directory_path() . '/' . $form_state['values']['cpn_path'],
    )), 'warning');
  }

  // Save the global files.
  foreach (array(
    'css',
    'js',
  ) as $type) {

    // Remove the existing file, if present.
    cpn_delete_file('global.' . $type);

    // If data was submitted, export it.
    if (!empty($form_state['values']['cpn_global_' . $type . '_agree']) && !empty($form_state['values']['cpn_global_' . $type])) {
      if (!empty($form_state['values']['cpn_global_' . $type])) {
        cpn_save_file($form_state['values']['cpn_global_' . $type], 'global.' . $type);
      }
    }
    else {
      $form_state['values']['cpn_global_' . $type] = '';
    }
  }
}