You are here

function tac_lite_admin_scheme_form in Taxonomy Access Control Lite 7

Same name and namespace in other branches
  1. 5 tac_lite.module \tac_lite_admin_scheme_form()
  2. 6 tac_lite.module \tac_lite_admin_scheme_form()

Returns the form for role-based privileges.

2 string references to 'tac_lite_admin_scheme_form'
tac_lite_admin_settings_scheme in ./tac_lite.module
Menu callback to create a form for each scheme.
tac_lite_create_form_alter in ./tac_lite_create.module
Implementation of hook_form_alter().

File

./tac_lite.module, line 228
Control access to site content based on taxonomy, roles and users.

Code

function tac_lite_admin_scheme_form($form, $form_state, $i) {
  $vids = variable_get('tac_lite_categories', NULL);
  $roles = user_roles();
  $config = _tac_lite_config($i);
  $form['#tac_lite_config'] = $config;
  if (count($vids)) {
    $form['tac_lite_config_scheme_' . $i] = array(
      '#tree' => TRUE,
    );
    $form['tac_lite_config_scheme_' . $i]['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Scheme name'),
      '#description' => t('A human-readable name for administrators to see. For example, \'read\' or \'read and write\'.'),
      '#default_value' => $config['name'],
      '#required' => TRUE,
    );

    // Currently, only view, update and delete are supported by node_access
    $options = array(
      'grant_view' => 'view',
      'grant_update' => 'update',
      'grant_delete' => 'delete',
    );
    $form['tac_lite_config_scheme_' . $i]['perms'] = array(
      '#type' => 'select',
      '#title' => t('Permissions'),
      '#multiple' => TRUE,
      '#options' => $options,
      '#default_value' => $config['perms'],
      '#description' => t('Select which permissions are granted by this scheme.  <br/>Note when granting update, it is best to enable visibility on all terms.  Otherwise a user may unknowingly remove invisible terms while editing a node.'),
      '#required' => FALSE,
    );
    $form['tac_lite_config_scheme_' . $i]['unpublished'] = array(
      '#type' => 'checkbox',
      '#title' => t('Apply to unpublished content'),
      '#description' => t('If checked, permissions in this scheme will apply to unpublished content.  If this scheme includes the view permission, then <strong>unpublished nodes will be visible</strong> to users whose roles would grant them access to the published node.'),
      '#default_value' => $config['unpublished'],
    );
    $form['tac_lite_config_scheme_' . $i]['term_visibility'] = array(
      '#type' => 'checkbox',
      '#title' => t('Visibility'),
      '#description' => t('If checked, this scheme determines whether a user can view <strong>terms</strong>.  Note the <em>view</em> permission in the select field above refers to <strong>node</strong> visibility.  This checkbox refers to <strong>term</strong> visibility, for example in a content edit form or tag cloud.'),
      '#default_value' => $config['term_visibility'],
    );
    $form['helptext'] = array(
      '#type' => 'markup',
      '#markup' => t('To grant to an individual user, visit the <em>access by taxonomy</em> tab on the account edit page.'),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
    $form['helptext2'] = array(
      '#type' => 'markup',
      '#markup' => t('To grant by role, select the terms below.'),
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    );
    $vocabularies = taxonomy_get_vocabularies();
    $all_defaults = variable_get('tac_lite_grants_scheme_' . $i, array());
    $form['tac_lite_grants_scheme_' . $i] = array(
      '#tree' => TRUE,
    );
    foreach ($roles as $rid => $role_name) {
      $form['tac_lite_grants_scheme_' . $i][$rid] = array(
        '#type' => 'fieldset',
        '#tree' => TRUE,
        '#title' => check_plain(t('Grant permission by role: !role', array(
          '!role' => $role_name,
        ))),
        '#description' => t(''),
        '#collapsible' => TRUE,
      );
      $defaults = isset($all_defaults[$rid]) ? $all_defaults[$rid] : NULL;
      foreach ($vids as $vid) {

        // Build a taxonomy select form element for this vocab
        $v = $vocabularies[$vid];
        $tree = taxonomy_get_tree($v->vid);
        $options = array(
          0 => '<' . t('none') . '>',
        );
        if ($tree) {
          foreach ($tree as $term) {
            $choice = new stdClass();
            $choice->option = array(
              $term->tid => str_repeat('-', $term->depth) . $term->name,
            );
            $options[] = $choice;
          }
        }
        $default_values = isset($defaults[$vid]) ? $defaults[$vid] : NULL;
        $form['tac_lite_grants_scheme_' . $i][$rid][$vid] = _tac_lite_term_select($v, $default_values);
      }
    }
    $form['tac_lite_rebuild'] = array(
      '#type' => 'checkbox',
      '#title' => t('Rebuild content permissions now'),
      '#default_value' => FALSE,
      // default false because usually only needed after scheme has been changed.
      '#description' => t('Do this once, after you have fully configured access by taxonomy.'),
      '#weight' => 9,
    );
    $form['#submit'][] = 'tac_lite_admin_scheme_form_submit';
    return system_settings_form($form);
  }
  else {
    $form['tac_lite_help'] = array(
      '#type' => 'markup',
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => t('First, select one or more vocabularies on the <a href=!url>settings tab</a>. Then, return to this page to complete configuration.', array(
        '!url' => url('admin/config/people/tac_lite/settings'),
      )),
    );
    return $form;
  }
}