/** * {@inheritdoc} */ public function validate($attribute, Constraint $constraint) { $referenceDataName = $attribute->getProperty('reference_data_name'); if (null !== $this->registry && in_array($attribute->getAttributeType(), $this->referenceDataType) && !$this->registry->has($referenceDataName)) { $references = array_keys($this->registry->all()); $this->context->buildViolation($constraint->message)->setParameter('%reference_data_name%', $referenceDataName)->setParameter('%references%', implode(', ', $references))->addViolation(); } }
/** * {@inheritdoc} */ public function transform($value, array $options = []) { if (null === $this->registry) { return null; } $value = trim($value); if (empty($value)) { return null; } if (!$this->registry->has($value)) { $references = array_keys($this->registry->all()); throw new \InvalidArgumentException(sprintf('Reference data "%s" does not exist. Allowed values are: %s', $value, implode(', ', $references))); } return $value; }
/** * @param string $value * * @throws \InvalidArgumentException */ protected function checkIfReferenceDataExists($value) { if (in_array($value['attributeType'], $this->referenceDataType)) { if (!$this->registry->has($value['reference_data_name'])) { $references = array_keys($this->registry->all()); throw new \InvalidArgumentException(sprintf('Reference data "%s" does not exist. Allowed values are: %s', $value['reference_data_name'], implode(', ', $references))); } } }