在国家/地区实体实体约束中添加欧盟

时间:2020-07-07 14:33:55

标签: symfony

我需要在实体字段的国家/地区列表中添加European Union。我从Symfony复制了CountryValidator.phpCountry.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,它将出现在该字段中。我该如何进行这项工作?

0 个答案:

没有答案
相关问题