You are here

function profile2_regpath_save_settings in Profile2 Registration Path 7

Same name and namespace in other branches
  1. 7.2 profile2_regpath.admin.inc \profile2_regpath_save_settings()

Helper function to save profile settings.

1 string reference to 'profile2_regpath_save_settings'
_profile2_regpath_form_profile2_type_form_alter in ./profile2_regpath.admin.inc
Implements hook_form_FORM_ID_alter().

File

./profile2_regpath.admin.inc, line 257
Modifications to administrative forms.

Code

function profile2_regpath_save_settings($form, &$form_state) {
  $profile_type = $form_state['values']['type'];
  $profile_id = profile2_regpath_get_profile_id($profile_type);

  // Define fields for db_merge.
  $fields = array(
    'path' => $form_state['values']['path'],
    'status' => $form_state['values']['status'],
    'weight' => $form_state['values']['weight'],
  );

  // Add roles if enabled.
  $roles = array();
  foreach ($form_state['values']['roles'] as $role_id => $enable) {
    if ($enable) {
      $roles[$role_id] = db_query("SELECT r.name FROM {role} AS r WHERE r.rid = :rid", array(
        ':rid' => $role_id,
      ))
        ->fetchField();
    }
  }
  $fields['roles'] = serialize($roles);

  // Create array of miscellaneous display options.
  $fields['misc'] = serialize(array(
    'fieldset_wrap' => $form_state['values']['fieldset_wrap'],
    'custom_titles' => $form_state['values']['custom_titles'],
    'login_title' => $form_state['values']['login_title'],
    'register_title' => $form_state['values']['register_title'],
    'password_title' => $form_state['values']['password_title'],
    'confirmation_display' => $form_state['values']['confirmation_display'],
    'confirmation_message' => $form_state['values']['confirmation_message'],
  ));

  // Add settings to database.
  $fields['profile_type'] = $profile_type;
  $fields['profile_id'] = $profile_id;
  profile2_regpath_regpath_save($fields);

  // Rebuild menu.
  if (menu_rebuild()) {
    drupal_set_message(t('The menu system has been rebuilt.'));
  }
}