You are here

protected function PasswordPolicyValidator::getApplicablePolicies in Password Policy 8.3

Gets policies applicable to the given roles.

Parameters

$roles: Roles.

Return value

array Applicable policies.

2 calls to PasswordPolicyValidator::getApplicablePolicies()
PasswordPolicyValidator::buildPasswordPolicyConstraintsTableRows in src/PasswordPolicyValidator.php
Builds the password policy constraints table rows.
PasswordPolicyValidator::validatePassword in src/PasswordPolicyValidator.php
Validates the given password.

File

src/PasswordPolicyValidator.php, line 159

Class

PasswordPolicyValidator

Namespace

Drupal\password_policy

Code

protected function getApplicablePolicies($roles) : array {
  $applicable_policies = [];
  foreach ($roles as $role) {
    if ($role) {
      $role_map = [
        'roles.' . $role => $role,
      ];
      $role_policies = $this->passwordPolicyStorage
        ->loadByProperties($role_map);

      /** @var \Drupal\password_policy\Entity\PasswordPolicy $policy */
      foreach ($role_policies as $policy) {
        if (!array_key_exists($policy
          ->id(), $applicable_policies)) {
          $applicable_policies[$policy
            ->id()] = $policy;
        }
      }
    }
  }
  return $applicable_policies;
}