You are here

public function PrivateMessageThreadMemberConstraintValidator::validate in Private Message 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Validation/Constraint/PrivateMessageThreadMemberConstraintValidator.php \Drupal\private_message\Plugin\Validation\Constraint\PrivateMessageThreadMemberConstraintValidator::validate()

File

src/Plugin/Validation/Constraint/PrivateMessageThreadMemberConstraintValidator.php, line 19

Class

PrivateMessageThreadMemberConstraintValidator
Private message thread constraint validator.

Namespace

Drupal\private_message\Plugin\Validation\Constraint

Code

public function validate($items, Constraint $constraint) {
  $users = $items
    ->referencedEntities();
  foreach ($users as $user) {
    if (!$user
      ->hasPermission('use private messaging system')) {
      $this->context
        ->addViolation($constraint->userPrivateMessagePermissionError, [
        '%user' => $user
          ->getDisplayName(),
      ]);
    }
  }
}