我需要在实体字段的国家/地区列表中添加European Union
。我从Symfony复制了CountryValidator.php
和Country.php
约束到我的包中,并修改了validate函数以包含European Union
。
$value = (string) $value;
$countries = Intl::getRegionBundle()->getCountryNames();
$countries['EU'] = 'European Union';
if (!isset($countries[$value])) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Country::NO_SUCH_COUNTRY_ERROR)
->addViolation();
}
我将这些约束作为CustomAssert
导入我的实体,并在字段中用作@CustomAssert\Country
我要面对的问题是,当我从国家/地区列表中显示实体添加/编辑时。
如果我添加@Assert\Country
,它将出现在该字段中。我该如何进行这项工作?