private function UniqueEntityTitleValidator::isNotUnique in Unique entity title 8
Is Not unique?
Parameters
string $unique_field: The name of unique field.
string $value: Value of the field to check for uniqueness.
string $entity_type_id: Id of the Entity Type.
string $bundle_field: Field of the Entity type.
string $bundle: Bundle of the entity.
string $id_field: Id field of the entity.
Return value
bool Whether the entity is unique or not
1 call to UniqueEntityTitleValidator::isNotUnique()
- UniqueEntityTitleValidator::validate in src/
Plugin/ Validation/ Constraint/ UniqueEntityTitleValidator.php
File
- src/
Plugin/ Validation/ Constraint/ UniqueEntityTitleValidator.php, line 67
Class
- UniqueEntityTitleValidator
- Validates the UniqueEntityTitle constraint.
Namespace
Drupal\unique_entity_title\Plugin\Validation\ConstraintCode
private function isNotUnique($unique_field, $value, $entity_type_id, $bundle_field, $bundle, $id_field) {
if (!empty($entity_type_id)) {
$query = \Drupal::entityQuery($entity_type_id)
->condition($unique_field, $value)
->condition($bundle_field, $bundle)
->range(0, 1);
// Exclude the current entity.
if (!empty($id = $this->context
->getRoot()
->getEntity()
->id())) {
$query
->condition($id_field, $id, '!=');
}
$entities = $query
->execute();
}
if (!empty($entities)) {
return TRUE;
}
return FALSE;
}