You are here

function tft_taxonomy_term_access in Taxonomy File Tree 8

Same name and namespace in other branches
  1. 3.x tft.module \tft_taxonomy_term_access()

Implements hook_ENTITY_TYPE_access().

File

./tft.module, line 596
Contains tft.module.

Code

function tft_taxonomy_term_access(TermInterface $entity, $operation, AccountInterface $account) {
  if ($entity
    ->bundle() !== 'tft_tree') {
    return AccessResult::neutral();
  }
  $tid = $entity
    ->id();
  $gid = _tft_get_group_gid($tid);
  if (!$gid) {
    return AccessResult::neutral();
  }
  $group = Group::load($gid);
  switch ($operation) {
    case 'view':
      return AccessResult::allowedIf(_tft_term_access($tid, $account));
    case 'update':
      if ($account
        ->hasPermission(TFT_ADD_TERMS)) {
        return AccessResult::allowed();
      }
      if (isset($group) && $group
        ->hasPermission(TFT_ADD_TERMS, $account)) {
        return AccessResult::allowed();
      }
      return AccessResult::neutral();
    case 'delete':
      if ($account
        ->hasPermission(TFT_DELETE_TERMS)) {
        return AccessResult::allowed();
      }
      if (isset($group) && $group
        ->hasPermission(TFT_DELETE_TERMS, $account)) {
        return AccessResult::allowed();
      }
      return AccessResult::neutral();
    case 'reorder':
      if ($account
        ->hasPermission(TFT_REORDER_TERMS)) {
        return AccessResult::allowed();
      }
      if (isset($group) && $group
        ->hasPermission(TFT_REORDER_TERMS, $account)) {
        return AccessResult::allowed();
      }
      return AccessResult::neutral();
    default:
      return AccessResult::neutral();
  }
}