You are here

function notifications_object_options_form_submit in Notifications 6.4

Process submission

1 call to notifications_object_options_form_submit()
notifications_subscriptions_options_form_submit in ./notifications.module
Wrapper submit callback se we can do an include before actual submission

File

includes/object.inc, line 462
Notifications object and fields

Code

function notifications_object_options_form_submit($form, $form_state) {
  $enabled = $disabled = 0;

  // We may have also send method and destination in this form, like on forms from anonymous users
  $send_method = isset($form_state['values']['send_method']) ? $form_state['values']['send_method'] : NULL;
  $destination = isset($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL;
  foreach ($form_state['values']['subscriptions']['options'] as $index => $value) {
    $subscription = $form_state['values']['subscriptions']['params'][$index];
    if ($value && !$subscription
      ->is_instance()) {

      // We checked a disabled subscription
      if ($send_method) {
        $subscription->send_method = $send_method;
      }
      if ($destination) {
        $subscription
          ->set_destination($destination);
      }
      notifications_save_subscription($subscription);
      $enabled++;
    }
    elseif (!$value && $subscription
      ->is_instance()) {

      // we unchecked an enabled subscription
      notifications_subscription_delete($subscription->sid);
      $disabled++;
    }
  }
  if ($enabled) {
    drupal_set_message(format_plural($enabled, 'A subscription has been created', '@count subscriptions have been created'));
  }
  if ($disabled) {
    drupal_set_message(format_plural($disabled, 'A subscription has been deleted', '@count subscriptions have been deleted'));
  }
}