entityManager = $entityManager; $this->ipnSuggestSettings = $ipnSuggestSettings; } public function validate($value, Constraint $constraint): void { if (null === $value || '' === $value) { return; } //If the autoAppendSuffix option is enabled, the IPN becomes unique automatically later if ($this->ipnSuggestSettings->autoAppendSuffix) { return; } if (!$constraint instanceof UniquePartIpnConstraint) { return; } /** @var Part $currentPart */ $currentPart = $this->context->getObject(); if (!$currentPart instanceof Part) { return; } $repository = $this->entityManager->getRepository(Part::class); $existingParts = $repository->findBy(['ipn' => $value]); foreach ($existingParts as $existingPart) { if ($currentPart->getId() !== $existingPart->getId()) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $value) ->addViolation(); } } } }