You are here

function vppr_access in Vocabulary Permissions Per Role 8

Access callback for common VPPR taxonomy operations.

3 calls to vppr_access()
VocabularyListBuilder::load in src/VocabularyListBuilder.php
Override Drupal\Core\Config\Entity\ConfigEntityListBuilder::load().
vppr_entity_access in ./vppr.module
Implements hook_entity_access()
vppr_route_access in ./vppr.module
Route access callback.

File

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

Code

function vppr_access($op = NULL, $vocabulary_id = NULL) {
  $perm = VpprPermissions::permissions();

  // Admin: always.
  if (Drupal::currentUser()
    ->hasPermission('administer taxonomy')) {
    return TRUE;
  }
  if ($op == 'index') {

    // Vocabulary list page.
    foreach ($perm as $key => $value) {

      // Check permission for each individual vocab so that to display
      // in the list or not.
      if (Drupal::currentUser()
        ->hasPermission($key)) {
        return TRUE;
      }
    }
  }
  else {

    // If option is not set i.e all the other options except vocabulary listing.
    if ($vocabulary_id) {
      if (Drupal::currentUser()
        ->hasPermission('administer ' . $vocabulary_id . ' vocabulary terms')) {
        return TRUE;
      }
    }
  }
  return FALSE;
}