You are here

public function NodeEntityBundleInfo::getPermissions in Permissions by Term 8

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

Return value

array

File

src/Service/NodeEntityBundleInfo.php, line 96

Class

NodeEntityBundleInfo
Class Info

Namespace

Drupal\permissions_by_term\Service

Code

public function getPermissions() {
  $returnArray = null;
  $permittedUsers = $this->database
    ->select('permissions_by_term_user', 'pu')
    ->fields('pu', [
    'uid',
    'tid',
  ])
    ->execute()
    ->fetchAll();
  $permittedRoles = $this->database
    ->select('permissions_by_term_role', 'pr')
    ->fields('pr', [
    'rid',
    'tid',
  ])
    ->execute()
    ->fetchAll();
  if (!empty($permittedRoles)) {
    $returnArray['roleLabels'] = [];
    foreach ($permittedRoles as $permittedRole) {
      $role = Role::load($permittedRole->rid);
      if (!empty($role)) {
        $returnArray['roleLabels'][$permittedRole->tid][] = $role
          ->label();
      }
    }
  }
  if (!empty($permittedUsers)) {
    $returnArray['userDisplayNames'] = [];
    foreach ($permittedUsers as $permittedUser) {
      $user = User::load($permittedUser->uid);
      if (!empty($user)) {
        $returnArray['userDisplayNames'][$permittedUser->tid][] = $user
          ->getDisplayName();
      }
    }
  }
  return $returnArray;
}