function push_notifications_admin_form_submit in Push Notifications 7
Submit callback for push notification configuration page.
File
- includes/
push_notifications.admin.inc, line 317 - Admin files for Push Notifications module.
Code
function push_notifications_admin_form_submit($form, &$form_state) {
// Module settings.
variable_set('push_notifications_require_enabled_language', $form_state['values']['push_notifications_require_enabled_language']);
variable_set('push_notifications_privatemsg_integration', $form_state['values']['push_notifications_privatemsg_integration']);
$apns_environment = $form_state['values']['push_notifications_apns_environment'];
switch ($apns_environment) {
// Development Environment.
case 0:
// Set the variables for the apns development environment.
variable_set('push_notifications_apns_environment', $apns_environment);
// Set the individual variables.
variable_set('push_notifications_apns_host', 'gateway.sandbox.push.apple.com');
variable_set('push_notifications_apns_certificate', 'apns-development' . PUSH_NOTIFICATIONS_APNS_CERTIFICATE_RANDOM . '.pem');
break;
case 1:
// Set the variables for the apns production environment.
variable_set('push_notifications_apns_environment', $apns_environment);
// Set the individual variables.
variable_set('push_notifications_apns_host', 'gateway.push.apple.com');
variable_set('push_notifications_apns_certificate', 'apns-production' . PUSH_NOTIFICATIONS_APNS_CERTIFICATE_RANDOM . '.pem');
break;
}
variable_set('push_notifications_google_type', $form_state['values']['push_notifications_google_type']);
// Set C2DM credentials.
variable_set('push_notifications_c2dm_username', $form_state['values']['push_notifications_c2dm_username']);
variable_set('push_notifications_c2dm_password', $form_state['values']['push_notifications_c2dm_password']);
// Set GCM API key.
variable_set('push_notifications_gcm_api_key', $form_state['values']['push_notifications_gcm_api_key']);
// Set FCM token.
variable_set('push_notifications_fcm_cloud_messaging_token', $form_state['values']['push_notifications_fcm_cloud_messaging_token']);
variable_set('push_notifications_fcm_server_key', $form_state['values']['push_notifications_fcm_server_key']);
// Set the APNS certificate location.
$apns_cert_folder = check_plain($form_state['values']['push_notifications_apns_certificate_folder']);
if (!empty($apns_cert_folder)) {
// Add a trailing slash if not present.
if ($apns_cert_folder[strlen($apns_cert_folder) - 1] != DIRECTORY_SEPARATOR) {
$apns_cert_folder .= DIRECTORY_SEPARATOR;
}
variable_set('push_notifications_apns_certificate_folder', $apns_cert_folder);
}
else {
variable_del('push_notifications_apns_certificate_folder');
}
// Check if the certificate exists.
$apns_cert = _push_notifications_get_apns_certificate();
if (!file_exists($apns_cert)) {
drupal_set_message(t('Could not find any APNS certificates at @path. Please ensure your certificates are located in the correct folder to send push notifications and are named correctly.', array(
'@path' => $apns_cert,
)), 'warning', FALSE);
}
// Set the APNS pem file passphrase.
variable_set('push_notifications_apns_passphrase', $form_state['values']['passphrase']);
// Set the APNS stream limit.
variable_set('push_notifications_apns_stream_context_limit', $form_state['values']['stream_context_limit']);
variable_set('push_notifications_set_entrust_certificate', $form_state['values']['push_notifications_set_entrust_certificate']);
$replacements = array(
'@environment' => $apns_environment ? "Production" : "Development",
);
drupal_set_message(t('The APNS environment was successfully set to "@environment".', $replacements));
}