CRUDlex\UniqueValidator::isValidUnique PHP Method

isValidUnique() protected method

Performs the regular unique validation.
protected isValidUnique ( $value, AbstractData $data, Entity $entity, $field ) : boolean
$value the value to validate
$data AbstractData the data instance to validate with
$entity Entity the entity of the field
$field the field to validate
return boolean true if everything is valid
    protected function isValidUnique($value, AbstractData $data, Entity $entity, $field)
    {
        $params = [$field => $value];
        $paramsOperators = [$field => '='];
        if ($entity->get('id') !== null) {
            $params['id'] = $entity->get('id');
            $paramsOperators['id'] = '!=';
        }
        $amount = intval($data->countBy($data->getDefinition()->getTable(), $params, $paramsOperators, true));
        return $amount == 0;
    }