You are here

function userprotect_get_user_protection_rules in User protect 8

Returns the protection rules that apply for the given account.

Parameters

\Drupal\user\UserInterface $account: The account to get protection rules for.

Return value

array A list of \Drupal\userprotect\Entity\ProtectionRuleInterface instances.

1 call to userprotect_get_user_protection_rules()
userprotect_user_access in ./userprotect.module
Implements hook_ENTITY_TYPE_access() for entity type "user".

File

./userprotect.module, line 261
Allows admins to protect users from being edited or cancelled.

Code

function userprotect_get_user_protection_rules(UserInterface $account) {
  $query = \Drupal::entityQuery('userprotect_rule');
  $group_user = $query
    ->andConditionGroup()
    ->condition('protectedEntityTypeId', 'user')
    ->condition('protectedEntityId', $account
    ->id());
  $group_user_role = $query
    ->andConditionGroup()
    ->condition('protectedEntityTypeId', 'user_role')
    ->condition('protectedEntityId', $account
    ->getRoles());
  $group = $query
    ->orConditionGroup()
    ->condition($group_user)
    ->condition($group_user_role);
  $entity_ids = $query
    ->condition($group)
    ->execute();
  return \Drupal::entityTypeManager()
    ->getStorage('userprotect_rule')
    ->loadMultiple($entity_ids);
}