WIP: Extend and improve profile editing
This commit is contained in:
@@ -2,29 +2,22 @@
|
||||
|
||||
namespace App\Form\ChoiceLoader;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\ApiClientException;
|
||||
use App\BusProNet\Model\CountriesResponse;
|
||||
use App\BusProNet\DataProvider\Countries;
|
||||
use App\BusProNet\Model\Country;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
|
||||
class BpnCountryChoiceLoader implements ChoiceLoaderInterface
|
||||
{
|
||||
public function __construct(private readonly ApiClient $apiClient, private readonly string $property)
|
||||
public function __construct(private readonly Countries $countries, private readonly string $property)
|
||||
{}
|
||||
|
||||
public function loadChoiceList(callable $value = null): ChoiceListInterface
|
||||
{
|
||||
try {
|
||||
/** @var CountriesResponse $response */
|
||||
$response = $this->apiClient->getCountries();
|
||||
$countries = $response->getCountries();
|
||||
} catch (ApiClientException $e) {
|
||||
$countries = [];
|
||||
}
|
||||
|
||||
$choices = [];
|
||||
/** @var Country[] $countries */
|
||||
$countries = $this->countries->getAll();
|
||||
|
||||
foreach ($countries as $country) {
|
||||
$key = 'nationality' === $this->property ? $country->getNationality() : $country->getName();
|
||||
|
||||
Reference in New Issue
Block a user