fix: accept the ISO-2 country codes when authoring a destination
This commit is contained in:
1 parent
169a17e19c
commit
5c7e702eab
3 files changed
+112
-9
No files matched your search
@@ -7,10 +7,26 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class DestinationDto
|
||||
{
|
||||
/**
|
||||
* The countries a destination can be authored in, as German label => ISO-3166-1 alpha-2.
|
||||
*
|
||||
* Both the form's choice list and the constraint below read this one map. They used to
|
||||
* spell the codes out twice and drifted apart the moment the stored values moved to
|
||||
* ISO-2: the form offered 'at' while the constraint still only accepted 'a'.
|
||||
*/
|
||||
public const COUNTRIES = [
|
||||
'Österreich' => 'at',
|
||||
'Schweiz' => 'ch',
|
||||
'Frankreich' => 'fr',
|
||||
'Italien' => 'it',
|
||||
'Deutschland' => 'de',
|
||||
'Niederlande' => 'nl',
|
||||
];
|
||||
|
||||
#[Assert\NotBlank(message: 'Bitte angeben')]
|
||||
private ?string $product = null;
|
||||
|
||||
#[Assert\Choice(choices: ['a', 'ch', 'd', 'f', 'i', 'nl'], message: 'Ungültige Auswahl')]
|
||||
#[Assert\Choice(callback: 'countryCodes', message: 'Ungültige Auswahl')]
|
||||
private ?string $country = null;
|
||||
|
||||
#[Assert\NotNull(message: 'Bitte das Beginndatum angeben')]
|
||||
@@ -46,6 +62,14 @@ class DestinationDto
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function countryCodes(): array
|
||||
{
|
||||
return array_values(self::COUNTRIES);
|
||||
}
|
||||
|
||||
public function getProduct(): ?string
|
||||
{
|
||||
return $this->product;
|
||||
|
||||
Reference in new issue
Block a user