-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Custom CountryType for list only countries without territories
- Loading branch information
Showing
17 changed files
with
56 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Form; | ||
|
||
use App\Address\AddressInterface; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\CountryType as SfCountryType; | ||
use Symfony\Component\Intl\Countries; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class CountryType extends AbstractType | ||
{ | ||
private const EXCLUDED_TERRITORIES = [ | ||
'GP', 'MQ', 'GF', 'RE', 'PM', 'YT', 'BL', 'MF', 'WF', 'PF', 'NC', 'TF', // Territoires français | ||
'AI', 'BM', 'IO', 'FK', 'GI', 'MS', 'PN', 'SH', 'TC', 'VG', // Territoires britanniques | ||
'AS', 'GU', 'MP', 'PR', 'UM', 'VI', // Territoires américains | ||
'AW', 'CW', 'SX', 'BQ', // Territoires néerlandais | ||
'CC', 'CX', 'HM', 'NF', // Territoires australiens | ||
'CK', 'NU', 'TK', // Autres territoires | ||
]; | ||
|
||
public function configureOptions(OptionsResolver $resolver): void | ||
{ | ||
$countries = Countries::getNames(); | ||
$filteredCountries = array_filter($countries, function ($code) { | ||
return !\in_array($code, self::EXCLUDED_TERRITORIES, true); | ||
}, \ARRAY_FILTER_USE_KEY); | ||
|
||
$resolver->setDefaults([ | ||
'choices' => $filteredCountries, | ||
'label' => 'Pays', | ||
'preferred_choices' => [AddressInterface::FRANCE], | ||
]); | ||
} | ||
|
||
public function getParent(): string | ||
{ | ||
return SfCountryType::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters