You are here

function simplenews_roles_form_simplenews_admin_category_form_alter in Simplenews Roles 7

Implements hook_form_FORM_ID_alter().

Add our settings to the newsletter add/edit settings page.

File

./simplenews_roles.module, line 25
Synchronize user subscriptions based on user roles membership.

Code

function simplenews_roles_form_simplenews_admin_category_form_alter(&$form, $form_state) {
  $role_newsletters = variable_get('simplenews_roles_tids_rids', array());
  $auto_remove = variable_get('simplenews_roles_auto_remove', array());
  $form['simplenews_roles'] = array(
    '#type' => 'fieldset',
    '#title' => t('Role synchronization'),
    '#collapsible' => FALSE,
    '#description' => t('This newsletter subscription list will consist of only users in the selected roles. This newsletter subscription is automatically syncronized so any users manually added to this list will be removed if they are not in any of the selected roles. If you want to change this behavior, turn off the auto remove checkbox at the bottom of the list.'),
  );
  $form['simplenews_roles']['roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Automatically subscribe users in the following roles to this newsletter'),
    '#options' => user_roles(TRUE),
    '#default_value' => isset($role_newsletters[$form['tid']['#value']]) ? $role_newsletters[$form['tid']['#value']] : array(),
  );
  $form['simplenews_roles']['auto_remove'] = array(
    '#type' => 'checkbox',
    '#title' => 'Auto remove',
    '#default_value' => isset($auto_remove[$form['tid']['#value']]) ? $auto_remove[$form['tid']['#value']] : 1,
  );
  $form['#submit'][] = 'simplenews_roles_newsletter_submit';
}