Release 2.13 (#4659)
This commit is contained in:
@@ -9,9 +9,12 @@
|
||||
|
||||
namespace App\Form\Toolbar;
|
||||
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\Query\CustomerQuery;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Intl\Countries;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
/**
|
||||
@@ -22,9 +25,38 @@ final class CustomerToolbarForm extends AbstractType
|
||||
{
|
||||
use ToolbarFormTrait;
|
||||
|
||||
public function __construct(private readonly CustomerRepository $customerRepository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$this->addSearchTermInputField($builder);
|
||||
|
||||
// fetch countries
|
||||
$qb = $this->customerRepository->createQueryBuilder('c');
|
||||
$qb
|
||||
->select('c.country')
|
||||
->distinct(true);
|
||||
|
||||
$countries = $qb->getQuery()->getSingleColumnResult();
|
||||
$choices = [];
|
||||
foreach ($countries as $country) {
|
||||
if (\is_string($country) && \is_string($options['locale'])) {
|
||||
$choices[$country] = Countries::getName($country, $options['locale']);
|
||||
}
|
||||
}
|
||||
|
||||
if (\count($choices) > 0) {
|
||||
$choices = array_flip($choices);
|
||||
ksort($choices);
|
||||
$builder->add('country', ChoiceType::class, [
|
||||
'label' => 'country',
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->addVisibilityChoice($builder);
|
||||
$this->addPageSizeChoice($builder);
|
||||
$this->addHiddenPagination($builder);
|
||||
@@ -37,6 +69,8 @@ final class CustomerToolbarForm extends AbstractType
|
||||
$resolver->setDefaults([
|
||||
'data_class' => CustomerQuery::class,
|
||||
'csrf_protection' => false,
|
||||
'locale' => locale_get_default(),
|
||||
]);
|
||||
$resolver->setAllowedTypes('locale', ['string']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ final class TagsType extends AbstractType
|
||||
private ?int $count = null;
|
||||
|
||||
public function __construct(
|
||||
private AuthorizationCheckerInterface $auth,
|
||||
private TagRepository $repository
|
||||
private readonly AuthorizationCheckerInterface $auth,
|
||||
private readonly TagRepository $repository
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user