You are here

function og_notifications_form_alter in Organic groups 5

Same name and namespace in other branches
  1. 5.8 og_notifications/og_notifications.module \og_notifications_form_alter()
  2. 5.3 og_notifications/og_notifications.module \og_notifications_form_alter()
  3. 5.7 og_notifications/og_notifications.module \og_notifications_form_alter()
  4. 6.2 modules/og_notifications/og_notifications.module \og_notifications_form_alter()
  5. 6 modules/og_notifications/og_notifications.module \og_notifications_form_alter()

Implementation of hook_form_alter().

File

og_notifications/og_notifications.module, line 54
Subscriptions to content in groups.

Code

function og_notifications_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'notifications_content_settings_form':
      $form['group'] = array(
        '#type' => 'fieldset',
        '#title' => t('Group subscriptions'),
        '#collapsible' => TRUE,
        '#weight' => 0,
      );

      // General content settings
      $select = array();
      $nodetypes = node_get_types();
      $ogtypes = og_get_types('group_post');
      foreach ($ogtypes as $ntype) {
        $select[$ntype] = $nodetypes[$ntype]->name;
      }
      $form['group']['og_notifications_content_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Allowed content types'),
        '#default_value' => variable_get('og_notifications_content_types', array()),
        '#options' => $select,
        '#description' => t('Select specific content types which should be <em>allowed</em> for subscriptions to <em>group + content type</em>.'),
        '#multiple' => TRUE,
      );
      break;
    case 'user_edit':

      // TODO: Is perm checking necessary here?
      // Insert autosubscribe option into the messaging section of the user edit
      // form.
      $account = $form['_account']['#value'];

      // TODO: Strings need to conform with OG and notifications terminology.
      $form['messaging']['og_notifications_autosubscribe'] = array(
        '#type' => 'checkbox',
        '#title' => t('Automatically enable notifications for any organic groups that I join.'),
        '#description' => t('Group notifications can be <a href="!manage-url">customised</a> in greater detail if necessary.', array(
          '!manage-url' => url('user/' . $account->uid . '/notifications/group'),
        )),
        '#default_value' => isset($account->og_notifications_autosubscribe) ? $account->og_notifications_autosubscribe : variable_get('og_notifications_autosubscribe', 1),
      );
      break;
    case 'og_admin_settings':

      // Insert the global autosubsribe checkbox into the OG administration
      // page. The fieldset should probably be renamed?
      $form['og_settings']['email']['og_notifications_autosubscribe'] = array(
        '#type' => 'checkbox',
        '#title' => t('Autosubscribe users to any groups that they join.'),
        '#description' => t('Automatically enable notifications by default. Users can override this via their account page.'),
        '#default_value' => variable_get('og_notifications_autosubscribe', 1),
        '#weight' => -1,
      );
      break;
  }
}