You are here

function notifications_ui_options_form_submit in Notifications 6.2

Same name and namespace in other branches
  1. 6 notifications_ui/notifications_ui.module \notifications_ui_options_form_submit()
  2. 6.3 notifications_ui/notifications_ui.module \notifications_ui_options_form_submit()

Form submission, node subscriptions form

1 call to notifications_ui_options_form_submit()
notifications_ui_notifications in notifications_ui/notifications_ui.module
Implementation of hook_notifications.
1 string reference to 'notifications_ui_options_form_submit'
notifications_ui_options_form in notifications_ui/notifications_ui.module
Form for node subscriptions @ TODO: offer the same form in a block to be put in the contents region.

File

notifications_ui/notifications_ui.module, line 317
User Interface for subscriptions modules

Code

function notifications_ui_options_form_submit($form, &$form_state) {
  $enabled = $disabled = 0;
  $form_values = $form_state['values'];
  $uid = $form_values['subscriptions']['account']->uid;
  foreach ($form_values['subscriptions']['options'] as $index => $value) {
    $subscription = $form_values['subscriptions']['params'][$index] + array(
      'uid' => $uid,
      'event_type' => 'node',
    );
    if ($value && empty($subscription['sid'])) {
      notifications_save_subscription($subscription);
      $enabled++;
    }
    elseif (!$value && !empty($subscription['sid'])) {
      notifications_delete_subscription($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'));
  }
}