WIP: Extend and improve profile editing

This commit is contained in:
Björn Fromme
2023-10-01 16:39:32 +02:00
parent 6595fbec8a
commit d776d37cd5
27 changed files with 553 additions and 375 deletions
@@ -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();