You are here

function commentaccess_form_user_profile_form_alter in Comment Access 7

File

./commentaccess.module, line 285
Provides users with permissions for comments on nodes they own.

Code

function commentaccess_form_user_profile_form_alter(&$form, &$form_state) {
  if ($form['#user_category'] == 'account') {
    $account = $form['#user'];

    // Gets the current commentaccess settings for the user.
    $commentaccess_settings = _commentaccess_get_account_settings($account);

    // Iterate through node types, add checkbox if user has access
    foreach (node_type_get_types() as $node) {
      $type = $node->type;
      if (node_access('create', $type)) {
        if (user_access("approve comments on own {$type}") || user_access("administer comments on own {$type}")) {
          $form['commentaccess_settings']["commentaccess_skip_{$type}"] = array(
            '#type' => 'checkbox',
            '#title' => t("{$node->name}: skip comment approvals"),
            '#default_value' => $commentaccess_settings["commentaccess_skip_{$type}"],
            '#description' => t('Check this to allow other people to comment on your posts without approval (Administrators may always comment without approval).'),
          );
        }
      }
    }

    // If user has options, wrap them in a fieldset and provide e-mail option
    if (!empty($form['commentaccess_settings'])) {
      $commentaccess_settings_fieldset = array(
        '#type' => 'fieldset',
        '#title' => t('Comment Access Settings'),
        '#weight' => 5,
        '#collapsible' => TRUE,
      );
      $form['commentaccess_settings'] = array_merge($form['commentaccess_settings'], $commentaccess_settings_fieldset);
      $form['commentaccess_settings']['commentaccess_email'] = array(
        '#type' => 'checkbox',
        '#title' => t('Receive e-mail notifications'),
        '#default_value' => $commentaccess_settings["commentaccess_email"],
        '#description' => t('Check this to receive e-mail notifications when new comments need your approval.'),
      );
    }
  }
}