- πΊπΈUnited States caesius
This issue should now be resolved by π UniqueFieldValueValidator works only with single value fields Fixed
- Status changed to Closed: outdated
about 1 year ago 7:18pm 13 September 2023
Closer look at validator
/**
* {@inheritdoc}
*/
public function validate($items, Constraint $constraint) {
if (!$item = $items->first()) {
return;
}
$field_name = $items->getFieldDefinition()->getName();
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $items->getEntity();
$entity_type_id = $entity->getEntityTypeId();
$id_key = $entity->getEntityType()->getKey('id');
$value_taken = (bool) \Drupal::entityQuery($entity_type_id)
// The id could be NULL, so we cast it to 0 in that case.
->condition($id_key, (int) $items->getEntity()->id(), '<>')
->condition($field_name, $item->value)
->range(0, 1)
->count()
->execute();
if ($value_taken) {
$this->context->addViolation($constraint->message, [
'%value' => $item->value,
'@entity_type' => $entity->getEntityType()->getLowercaseLabel(),
'@field_name' => mb_strtolower($items->getFieldDefinition()->getLabel()),
]);
}
}
reviled that only first field item is check for duplicates.
Add test coverage and fix validator.
None
None
None
Closed: outdated
11.0 π₯
Last updated
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
This issue should now be resolved by π UniqueFieldValueValidator works only with single value fields Fixed