You are here

class PrivateMessageThreadMemberConstraintValidator in Private Message 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Validation/Constraint/PrivateMessageThreadMemberConstraintValidator.php \Drupal\private_message\Plugin\Validation\Constraint\PrivateMessageThreadMemberConstraintValidator

Private message thread constraint validator.

Ensures that all members of a private message thread have permission to use the private message thread.

Hierarchy

Expanded class hierarchy of PrivateMessageThreadMemberConstraintValidator

File

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

Namespace

Drupal\private_message\Plugin\Validation\Constraint
View source
class PrivateMessageThreadMemberConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  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(),
        ]);
      }
    }
  }

}

Members