You are here

function taxonomy_access_fix_access in Taxonomy access fix 7.2

Same name and namespace in other branches
  1. 8 taxonomy_access_fix.module \taxonomy_access_fix_access()
  2. 7 taxonomy_access_fix.module \taxonomy_access_fix_access()

Creates an access callback for custom vocabulary access.

See also

taxonomy_access_fix_permission()

http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func...

3 calls to taxonomy_access_fix_access()
taxonomy_access_fix_admin_menu_map in ./taxonomy_access_fix.module
Implements hook_admin_menu_map().
taxonomy_access_fix_form_taxonomy_overview_terms_alter in ./taxonomy_access_fix.module
Implements hook_form_FORM_ID_alter() for taxonomy_overview_terms().
taxonomy_access_fix_form_taxonomy_overview_vocabularies_alter in ./taxonomy_access_fix.module
Implements hook_form_FORM_ID_alter() for taxonomy_overview_vocabularies().
1 string reference to 'taxonomy_access_fix_access'
taxonomy_access_fix_menu_alter in ./taxonomy_access_fix.module
Implements hook_menu_alter().

File

./taxonomy_access_fix.module, line 146
This file contains all hooks and callbacks for extra/improved Taxonomy permissions.

Code

function taxonomy_access_fix_access($op, $vocabulary = NULL) {

  // Admin: always.
  if (user_access('administer taxonomy')) {
    return TRUE;
  }
  $access = FALSE;
  if ($vocabulary && is_string($vocabulary)) {
    $vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary);
  }

  // Others: well, that depends.
  switch ($op) {
    case 'index':

      // Allow access when the user has access to at least one vocabulary.
      foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
        if (user_access('edit terms in ' . $vid) || user_access('delete terms in ' . $vid) || user_access('add terms in ' . $vocabulary->machine_name)) {
          $access = TRUE;
          break;
        }
      }
      break;
    case 'list terms':
    case 'reorder':
      if ($vocabulary) {
        $vid = $vocabulary->vid;
        if (user_access('edit terms in ' . $vid) || user_access('delete terms in ' . $vid) || user_access('add terms in ' . $vocabulary->machine_name)) {
          $access = TRUE;
        }
      }
      break;
    case 'add terms':
      if ($vocabulary) {
        if (user_access('add terms in ' . $vocabulary->machine_name)) {
          $access = TRUE;
        }
      }
      break;
  }
  drupal_alter('taxonomy_access_fix', $op, $vocabulary, $access);
  return $access;
}