You are here

function _taxonomy_access_permissions_form in Taxonomy Access Control 5

Generating the category permissions form for choosen user role.

1 string reference to '_taxonomy_access_permissions_form'
_taxonomy_access_permissions_page in ./taxonomy_access_admin.inc
Menu callback; presents the category permissions page of TAC (admin/user/taxonomy_access).

File

./taxonomy_access_admin.inc, line 73
Administrative interface for taxonomy access control.

Code

function _taxonomy_access_permissions_form($rid) {
  $node_grant_types = array(
    'view',
    'update',
    'delete',
  );

  // Get all category permissions
  $perm = taxonomy_access_get_grants($rid);
  $default = taxonomy_access_get_default_grants($rid);
  $form['taxonomy_access'] = array(
    '#tree' => TRUE,
  );

  // Do the row for uncategorized nodes
  foreach ($node_grant_types as $grant) {
    $form['taxonomy_access'][0]['term'][0][$grant] = array(
      '#type' => 'checkbox',
      '#default_value' => $perm[0][$grant],
    );
  }
  $vocabs = taxonomy_get_vocabularies();
  $options1 = array(
    '3' => '--',
    '1' => t('Allow all'),
    '0' => t('Ignore all'),
    '2' => t('Deny all'),
  );
  $options2 = array(
    '3' => '--',
    '1' => t('Select all'),
    '0' => t('Deselect all'),
  );

  //Radios' values: '1' => t('Allow'), '0' => t('Ignore'), '2' => t('Deny')
  $radios = array(
    '1' => '',
    '0' => '',
    '2' => '',
  );
  foreach ($vocabs as $vocab) {
    $form['taxonomy_access'][$vocab->vid] = array(
      '#title' => $vocab->name,
      '#tree' => TRUE,
    );
    foreach ($node_grant_types as $grant) {
      $form['taxonomy_access'][$vocab->vid]['vocab'][$grant] = array(
        '#type' => 'select',
        '#options' => $options1,
        '#default_value' => -1,
      );
      $form['taxonomy_access'][$vocab->vid]['default'][$grant] = array(
        '#type' => 'radios',
        '#options' => $radios,
        '#default_value' => isset($default[$vocab->vid][$grant]) ? $default[$vocab->vid][$grant] : 0,
      );
    }
    foreach (array(
      'create',
      'list',
    ) as $grant) {
      $form['taxonomy_access'][$vocab->vid]['vocab'][$grant] = array(
        '#type' => 'select',
        '#options' => $options2,
      );
      $form['taxonomy_access'][$vocab->vid]['default'][$grant] = array(
        '#type' => 'checkbox',
        '#default_value' => isset($default[$vocab->vid][$grant]) ? $default[$vocab->vid][$grant] : 0,
      );
    }

    // Defining form elements for each term in vocabulary
    $terms = array();
    $terms = taxonomy_get_tree($vocab->vid);
    if ($terms) {
      foreach ($terms as $term) {
        foreach ($node_grant_types as $grant) {
          $form['taxonomy_access'][$vocab->vid]['term'][$term->tid][$grant] = array(
            '#type' => 'radios',
            '#options' => $radios,
            '#default_value' => isset($perm[$term->tid][$grant]) ? $perm[$term->tid][$grant] : 0,
          );
        }
        foreach (array(
          'create',
          'list',
        ) as $grant) {
          $form['taxonomy_access'][$vocab->vid]['term'][$term->tid][$grant] = array(
            '#type' => 'checkbox',
            '#default_value' => isset($perm[$term->tid][$grant]) ? $perm[$term->tid][$grant] : 0,
          );
        }
      }
    }
  }
  $form['taxonomy_access']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save category permissions'),
    '#name' => 'save',
    '#button_type' => 'submit',
  );
  return $form;
}