You are here

function _vppr_page_taxonomy_overview in Vocabulary Permissions Per Role 6

Page callback for taxonomy overview.

Displays the form core ships if $user has 'administer taxonomy' permission, or a simple list that mimics the same otherwise. Rationale: don't display even a stripped-down form if we don't need a form but only a nicely-formatted list.

See also

taxonomy_overview_vocabularies()

1 string reference to '_vppr_page_taxonomy_overview'
vppr_menu_alter in ./vppr.module
Implementation of hook_menu_alter().

File

./vppr.module, line 133
Vocabulary Permissions Per Role

Code

function _vppr_page_taxonomy_overview($form_id) {

  // If $user has 'administer taxonomy', then do not do anything, just bail
  // out early with the untouched form.
  if (user_access('administer taxonomy')) {
    return drupal_get_form($form_id);
  }
  $header = array(
    t('Name'),
    t('Type'),
    array(
      'data' => t('Operations'),
      'colspan' => '2',
    ),
  );
  $rows = array();
  $vocabularies = taxonomy_get_vocabularies();
  foreach ($vocabularies as $vocabulary) {
    if (!_vppr_access_vocabulary($vocabulary)) {
      continue;
    }
    $types = array();
    foreach ($vocabulary->nodes as $type) {
      $node_type = node_get_types('name', $type);
      $types[] = $node_type ? check_plain($node_type) : check_plain($type);
    }
    $rows[] = array(
      check_plain($vocabulary->name),
      implode(', ', $types),
      l(t('list terms'), "admin/content/taxonomy/{$vocabulary->vid}"),
      l(t('add terms'), "admin/content/taxonomy/{$vocabulary->vid}/add/term"),
    );
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No vocabularies available.'),
        'colspan' => '4',
      ),
    );
  }
  return theme('table', $header, $rows);
}