You are here

function tac_lite_admin_scheme_form in Taxonomy Access Control Lite 6

Same name and namespace in other branches
  1. 5 tac_lite.module \tac_lite_admin_scheme_form()
  2. 7 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
tac_lite_create_form_alter in ./tac_lite_create.module
Implementation of hook_form_alter().

File

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

Code

function tac_lite_admin_scheme_form($form_state, $i) {
  $vids = variable_get('tac_lite_categories', NULL);
  $roles = user_roles();
  if (count($vids)) {
    $config = _tac_lite_config($i);
    $form['#tac_lite_config'] = $config;
    $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]['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',
      '#value' => 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',
      '#value' => 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) {
        $v = $vocabularies[$vid];
        $form['tac_lite_grants_scheme_' . $i][$rid][$vid] = _taxonomy_term_select(check_plain($v->name), NULL, isset($defaults[$vid]) ? $defaults[$vid] : NULL, $vid, '', TRUE, '<' . t('none') . '>');
      }
    }
    $form['#submit'][] = 'tac_lite_admin_scheme_form_submit';
    return system_settings_form($form);
  }
  else {
    return array(
      'body' => array(
        '#type' => 'markup',
        '#value' => t('First select vocabularies on the <a href=!url>settings page</a>.', array(
          '!url' => url('admin/user/access/tac_lite'),
        )),
      ),
    );
  }
}