You are here

protected function WebformAccessRulesManager::checkAccessRule in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformAccessRulesManager.php \Drupal\webform\WebformAccessRulesManager::checkAccessRule()

Checks an access rule against a user account's roles and id.

Parameters

array $access_rule: An access rule.

\Drupal\Core\Session\AccountInterface $account: The user session for which to check access.

Return value

bool Returns a TRUE if access is allowed.

See also

\Drupal\webform\Plugin\WebformElementBase::checkAccessRule

2 calls to WebformAccessRulesManager::checkAccessRule()
WebformAccessRulesManager::checkAccessRules in src/WebformAccessRulesManager.php
Check access for a given operation and set of access rules.
WebformAccessRulesManager::checkWebformSubmissionAccess in src/WebformAccessRulesManager.php
Check if operation is allowed through access rules for a submission.

File

src/WebformAccessRulesManager.php, line 163

Class

WebformAccessRulesManager
The webform access rules manager service.

Namespace

Drupal\webform

Code

protected function checkAccessRule(array $access_rule, AccountInterface $account) {
  if (!empty($access_rule['roles']) && array_intersect($access_rule['roles'], $account
    ->getRoles())) {
    return TRUE;
  }
  elseif (!empty($access_rule['users']) && in_array($account
    ->id(), $access_rule['users'])) {
    return TRUE;
  }
  elseif (!empty($access_rule['permissions'])) {
    foreach ($access_rule['permissions'] as $permission) {
      if ($account
        ->hasPermission($permission)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}