You are here

function notifications_ui_form_alter in Notifications 6.4

Same name and namespace in other branches
  1. 5 notifications_ui/notifications_ui.module \notifications_ui_form_alter()
  2. 6 notifications_ui/notifications_ui.module \notifications_ui_form_alter()
  3. 6.2 notifications_ui/notifications_ui.module \notifications_ui_form_alter()
  4. 6.3 notifications_ui/notifications_ui.module \notifications_ui_form_alter()
  5. 7 notifications_ui/notifications_ui.module \notifications_ui_form_alter()

Implementation of hook_form_alter()

File

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

Code

function notifications_ui_form_alter(&$form, $form_state, $form_id) {
  global $user;

  // Content type settings
  switch ($form_id) {
    case 'node_type_form':
      if (isset($form['identity']['type'])) {
        module_load_include('admin.inc', 'notifications_ui');

        // Just in case we want to add more settings here
        $form['notifications']['notifications_node_ui'] = array(
          '#type' => 'checkboxes',
          '#title' => t('Subscriptions UI'),
          '#default_value' => notifications_ui_node_options($form['#node_type']->type),
          '#options' => _notifications_ui_node_options(),
          '#description' => t('Enable different display options for subscriptions to this content type.'),
        );
        if (!variable_get('notifications_ui_per_type', 0)) {
          $form['notifications']['notifications_node_ui']['#disabled'] = TRUE;
          $form['notifications']['notifications_node_ui']['#description'] .= ' <strong>' . t('To enable these options check the <a href="@notifications-ui-settings">Notifications UI settings</a>', array(
            '@notifications-ui-settings' => url('admin/messaging/notifications/ui'),
          )) . '</strong>';
        }
      }
      break;
    case 'comment_form':

      // Add to comment forms.
      $node = node_load($form['nid']['#value']);
      if ($subscriptions = notifications_ui_node_subscriptions($node, 'comment')) {
        $form[] = notifications_subscriptions_options_subform($subscriptions, FALSE);
      }
      break;
    case 'notifications_user_overview':

      // Create new subscription
      $account = $form['account']['#value'];
      foreach (notifications_ui_subscription_types() as $key => $type) {
        if (notifications_ui_type_enabled($key) && notifications_ui_user_options('create') && notifications_access_user_add($account, $key)) {
          $create[] = l($type['title'], "user/{$account->uid}/notifications/add/{$key}");
        }
      }
      if (!empty($create)) {

        // $output .= theme('item_list', $create, t('or create a new subscription'));
        $form['create'] = array(
          '#type' => 'item',
          '#weight' => 30,
          '#title' => t('or create a new subscription'),
          '#value' => theme('item_list', $create),
        );
      }
      break;
    default:
      if (isset($form['type']['#value']) && $form['type']['#value'] . '_node_form' == $form_id && ($subscriptions = notifications_ui_node_subscriptions($form['#node'], 'form'))) {
        $form = array_merge_recursive($form, notifications_subscriptions_options_subform($subscriptions, FALSE));
      }
  }
}