You are here

public function UniqueFieldConstraintValidator::BuildQuery in Unique field 8

1 call to UniqueFieldConstraintValidator::BuildQuery()
UniqueFieldConstraintValidator::validate in src/Plugin/Validation/Constraint/UniqueFieldConstraintValidator.php
Checks if the passed value is valid.

File

src/Plugin/Validation/Constraint/UniqueFieldConstraintValidator.php, line 57
Contains \Drupal\unique_field\Plugin\Validation\Constraint\UniqueFieldConstraintValidator.

Class

UniqueFieldConstraintValidator
Validates the UniqueField constraint.

Namespace

Drupal\unique_field\Plugin\Validation\Constraint

Code

public function BuildQuery($field_name, $field_value, $bundle = NULL, $scope = NULL) {
  if (!empty($scope)) {
    $query = \Drupal::entityQuery('node');
    switch ($scope) {
      case 'all':
        $query
          ->condition($field_name, $field_value, '=');
        break;
      case 'type':
        $query
          ->condition($field_name, $field_value, '=');
        $query
          ->condition('type', $bundle, '=');
        break;
    }
    $nids = $query
      ->execute();
    return $nids;
  }
}