You are here

protected function User::validateEntity in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::validateEntity()
  2. 10 core/modules/user/src/Plugin/views/argument_validator/User.php \Drupal\user\Plugin\views\argument_validator\User::validateEntity()

Validates an individual entity against class access settings.

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

Return value

bool True if validated.

Overrides Entity::validateEntity

1 call to User::validateEntity()
UserName::validateArgument in core/modules/user/src/Plugin/views/argument_validator/UserName.php
Performs validation for a given argument.

File

core/modules/user/src/Plugin/views/argument_validator/User.php, line 86

Class

User
Validate whether an argument is a valid user.

Namespace

Drupal\user\Plugin\views\argument_validator

Code

protected function validateEntity(EntityInterface $entity) {

  /** @var \Drupal\user\UserInterface $entity */
  $role_check_success = TRUE;

  // See if we're filtering users based on roles.
  if (!empty($this->options['restrict_roles']) && !empty($this->options['roles'])) {
    $roles = $this->options['roles'];
    if (!(bool) array_intersect($entity
      ->getRoles(), $roles)) {
      $role_check_success = FALSE;
    }
  }
  return $role_check_success && parent::validateEntity($entity);
}