You are here

protected function Notifications_Subscription_List::form_operation in Notifications 7

Form operation

1 call to Notifications_Subscription_List::form_operation()
Notifications_Subscription_List::form_submit in ./notifications.list.inc
Process form submission

File

./notifications.list.inc, line 301
Drupal Notifications Framework - Default class file

Class

Notifications_Subscription_List
List of subscriptions or subscription types

Code

protected function form_operation($operation, $form, &$form_state) {
  switch ($operation) {
    case 'cancel':
      break;
    case 'update':
      $options = $form_state['values']['subscriptions'];
      $subscribe = array_filter($options);
      $created = $deleted = 0;
      foreach ($this
        ->get_subscriptions() as $index => $subscription) {
        $status = in_array($index, $subscribe);
        if (!$subscription
          ->is_stored() && $status) {
          $subscription
            ->save();
          $created++;
        }
        elseif ($subscription
          ->is_stored() && !$status) {
          $subscription
            ->delete();
          $deleted++;
        }
      }
      if ($created || $deleted) {
        drupal_set_message(t('The subscriptions have been updated: created @created, deleted @deleted.', array(
          '@created' => $created,
          '@deleted' => $deleted,
        )));
      }
      break;
    case 'unsubscribe':
    case 'delete':
      $count = 0;
      foreach ($this
        ->get_instances() as $subscription) {
        $subscription
          ->delete();
        $count++;
      }
      $form_state['redirect'] = variable_get('notifications_frontpage', '<front>');
      drupal_set_message(format_plural($count, 'A subscription has been deleted.', '@count subscriptions have been deleted.'));
      break;
  }
}