You are here

function _forum_access_forum_form in Forum Access 7

Same name and namespace in other branches
  1. 6 forum_access.admin.inc \_forum_access_forum_form()

Rewrite the forum administration page with our new access rules.

1 call to _forum_access_forum_form()
forum_access_form_alter in ./forum_access.module
Implements hook_form_alter().

File

./forum_access.admin.inc, line 15
forum_access.admin.inc

Code

function _forum_access_forum_form(&$form, &$form_state, $is_container) {
  $tid = isset($form['tid']['#value']) ? $form['tid']['#value'] : NULL;
  if (isset($tid) && !forum_access_access('view', $tid, NULL, FALSE)) {
    drupal_access_denied();

    // Deny access if the user doesn't have View access.
    drupal_exit();
  }
  if (isset($tid)) {

    // edit
    $template_tid = variable_get('forum_access_default_template_tid', 0);
    $settings = _forum_access_get_settings($tid);
  }
  else {

    // create
    $template_tid = variable_get('forum_access_new_template_tid', NULL);
    $settings = _forum_access_get_settings($template_tid);
  }
  $fa_priority = $settings['priority'];
  foreach (module_implements('node_access_records') as $module) {
    $na_modules[$module] = $module;
  }
  unset($na_modules['forum_access']);
  unset($na_modules['acl']);
  $form['forum_access'] = array(
    '#type' => 'fieldset',
    '#title' => t('Access control'),
    '#collapsible' => TRUE,
    '#tree' => TRUE,
  );
  $form['forum_access']['permissions'] = _forum_access_forum_permissions_form($is_container);
  $form['forum_access']['template'] = _forum_access_forum_template_form($template_tid);
  $form['forum_access']['#after_build'][] = '_forum_access_forum_form_after_build_template';
  $form['forum_access']['grants'] = _forum_access_forum_grants_form($form_state, $is_container, $settings);
  $form['forum_access']['acl'] = _forum_access_forum_acl_form($form_state, $tid);
  $form['forum_access']['interference'] = _forum_access_forum_interference_form($is_container, $na_modules, $fa_priority);
  $form['forum_access']['troubleshooting'] = _forum_access_forum_troubleshooting_form($is_container, count($na_modules));
  if (!$is_container && isset($tid) && !node_access_needs_rebuild()) {
    $count = db_query("SELECT COUNT(DISTINCT ti.nid) FROM {taxonomy_index} ti WHERE ti.tid = :tid", array(
      ':tid' => $tid,
    ))
      ->fetchField();
    $limit = variable_get('forum_access_update_limit', 20);

    // for _node_access_rebuild_batch_operation()
    $threshold = variable_get('forum_access_batch_threshold', $limit);

    // change the variable if you want
    $form['forum_access']['update_limit'] = array(
      '#type' => 'value',
      '#value' => $limit,
    );
    $form['forum_access']['update_choice'] = array(
      '#type' => 'radios',
      '#title' => t('Update the permissions'),
      '#description' => t('<em>If</em> you make any node access changes, then each node in this forum needs to be updated. Hover over the radiobuttons for details.'),
      '#options' => array(
        0,
        1,
        2,
      ),
      0 => array(
        '#type' => 'radio',
        '#title' => t('for all %count nodes immediately', array(
          '%count' => $count,
        )),
        '#attributes' => array(
          'title' => t('This option is the fastest, but with many nodes it can still take considerable time and memory. If it does not complete, it will leave your !node_access table in an inconsistent state.', array(
            '!node_access' => '{node_access}',
          )),
        ),
        '#return_value' => 0,
        '#default_value' => $count <= $threshold ? 0 : 1,
        '#parents' => array(
          'forum_access',
          'update_choice',
        ),
      ),
      1 => array(
        '#type' => 'radio',
        '#title' => check_plain(t('in batches of !limit now', array(
          '!limit' => $limit,
        ))),
        '#attributes' => array(
          'title' => t('The batch option will always work reliably, but it takes longer to complete.'),
        ),
        '#return_value' => 1,
        '#default_value' => $count <= $threshold ? 0 : 1,
        '#parents' => array(
          'forum_access',
          'update_choice',
        ),
      ),
      2 => array(
        '#type' => 'radio',
        '#title' => t('rebuild <strong>all</strong> permissions later'),
        '#attributes' => array(
          'title' => t("This option will only set a flag to remind you to rebuild all permissions later; this is useful if you want to make multiple changes to your node access settings quickly and delay the updating until you're done."),
        ),
        '#return_value' => 2,
        '#default_value' => $count <= $threshold ? 0 : 1,
        '#parents' => array(
          'forum_access',
          'update_choice',
        ),
      ),
      '#attributes' => array(
        'class' => array(
          'forum-access-flowed',
        ),
      ),
    );
  }
  if (isset($tid)) {
    $form['forum_access']['force_update'] = array(
      '#type' => 'checkbox',
      '#title' => t('Update even if unchanged'),
    );
  }

  // Move some stuff down so our block goes in a nice place.
  $form['submit']['#weight'] = 10;
  $form['delete']['#weight'] = 10;
  $form['#validate'][] = '_forum_access_form_validate';
  $form['#submit'][] = '_forum_access_form_submit';
}