You are here

class SharedEmailUniqueValidator in Shared Email 8.2

Class SharedEmailUniqueValidator.

@package Drupal\sharedemail\Plugin\Validation\Constraint

Hierarchy

Expanded class hierarchy of SharedEmailUniqueValidator

File

src/Plugin/Validation/Constraint/SharedEmailUniqueValidator.php, line 13

Namespace

Drupal\sharedemail\Plugin\Validation\Constraint
View source
class SharedEmailUniqueValidator extends UniqueFieldValueValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($items, Constraint $constraint) {
    if (!($item = $items
      ->first())) {
      return;
    }
    if (\Drupal::currentUser()
      ->getAccount()
      ->hasPermission('create shared email account')) {
      $allowed = \Drupal::config('sharedemail.settings')
        ->get('sharedemail_allowed');
      if (empty($allowed) || stripos($allowed, $item->value) !== FALSE) {
        return;
      }
    }
    parent::validate($items, $constraint);
  }

}

Members