You are here

public function NodeViewCountRecordsManager::isRecordableForUserRole in Node view count 8

Checks whether node should be counted in statistics for given user role.

Parameters

\Drupal\Core\Session\AccountInterface $account: User account object to fetch roles from.

Return value

bool TRUE if node should be counted in statistics for given user role.

Overrides NodeViewCountRecordsManagerInterface::isRecordableForUserRole

1 call to NodeViewCountRecordsManager::isRecordableForUserRole()
NodeViewCountRecordsManager::getNodeViewsCount in src/NodeViewCountRecordsManager.php
Return count of node views.

File

src/NodeViewCountRecordsManager.php, line 113

Class

NodeViewCountRecordsManager
Provides a class for interacting with nodeviewcount records.

Namespace

Drupal\nodeviewcount

Code

public function isRecordableForUserRole(AccountInterface $account) {
  $tracked_user_roles = $this->config
    ->get('user_roles');
  $excluded_user_roles = $this->config
    ->get('excluded_user_roles');
  $is_checked_user_role = array_intersect($tracked_user_roles, $account
    ->getRoles()) !== [];
  $is_in_excluded_user_roles = array_intersect($excluded_user_roles, $account
    ->getRoles()) !== [];
  return $is_checked_user_role && !$is_in_excluded_user_roles;
}