WIP: Implement profile editing

This commit is contained in:
Björn Fromme
2023-09-17 19:36:18 +02:00
parent 97c5a686af
commit bfc5e5e242
17 changed files with 498 additions and 18 deletions
@@ -0,0 +1,47 @@
<?php
namespace App\Form\ChoiceLoader;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\BusProNet\Model\CountriesResponse;
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 loadChoiceList(callable $value = null): ChoiceListInterface
{
try {
/** @var CountriesResponse $response */
$response = $this->apiClient->getCountries();
$countries = $response->getCountries();
} catch (ApiClientException $e) {
$countries = [];
}
$choices = [];
foreach ($countries as $country) {
$key = 'nationality' === $this->property ? $country->getNationality() : $country->getName();
$choices[$key] = $country->getId();
}
return new ArrayChoiceList($choices);
}
public function loadChoicesForValues(array $values, callable $value = null): array
{
return $values;
}
public function loadValuesForChoices(array $choices, callable $value = null): array
{
return $choices;
}
}