You are here

public function AccessCheck::isAccessAllowedByDatabase in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 src/Service/AccessCheck.php \Drupal\permissions_by_term\Service\AccessCheck::isAccessAllowedByDatabase()

Parameters

int $tid:

bool|int $uid:

string $langcode:

Return value

bool

2 calls to AccessCheck::isAccessAllowedByDatabase()
AccessCheck::canUserAccessByNodeId in src/Service/AccessCheck.php
AccessChecker::isAccessAllowed in modules/permissions_by_entity/src/Service/AccessChecker.php
Checks if a user is allowed to access a fieldable entity.

File

src/Service/AccessCheck.php, line 95

Class

AccessCheck
AccessCheckService class.

Namespace

Drupal\permissions_by_term\Service

Code

public function isAccessAllowedByDatabase($tid, $uid = FALSE, $langcode = '') {
  $langcode = $langcode === '' ? \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId() : $langcode;
  if ($uid === FALSE || (int) $uid === 0) {
    $user = \Drupal::currentUser();
  }
  elseif (is_numeric($uid)) {
    $user = User::load($uid);
  }
  $tid = (int) $tid;
  if (!$this
    ->isAnyPermissionSetForTerm($tid, $langcode)) {
    return TRUE;
  }

  /* At this point permissions are enabled, check to see if this user or one
   * of their roles is allowed.
   */
  $aUserRoles = $user
    ->getRoles();
  foreach ($aUserRoles as $sUserRole) {
    if ($this
      ->isTermAllowedByUserRole($tid, $sUserRole, $langcode)) {
      return TRUE;
    }
  }
  $iUid = intval($user
    ->id());
  if ($this
    ->isTermAllowedByUserId($tid, $iUid, $langcode)) {
    return TRUE;
  }
  return FALSE;
}