|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
| 4 | + * |
| 5 | + * Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics) |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as published |
| 9 | + * by the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +declare(strict_types=1); |
| 22 | + |
| 23 | + |
| 24 | +namespace App\Form\Type; |
| 25 | + |
| 26 | +use Symfony\Component\DependencyInjection\Attribute\Autowire; |
| 27 | +use Symfony\Component\Form\AbstractType; |
| 28 | +use Symfony\Component\Form\Extension\Core\Type\LanguageType; |
| 29 | +use Symfony\Component\Form\Extension\Core\Type\LocaleType; |
| 30 | +use Symfony\Component\Intl\Languages; |
| 31 | +use Symfony\Component\OptionsResolver\OptionsResolver; |
| 32 | + |
| 33 | +class LanguageMenuEntriesType extends AbstractType |
| 34 | +{ |
| 35 | + public function __construct(#[Autowire(param: 'partdb.locale_menu')] private readonly array $preferred_languages) |
| 36 | + { |
| 37 | + |
| 38 | + } |
| 39 | + |
| 40 | + public function getParent(): string |
| 41 | + { |
| 42 | + return LanguageType::class; |
| 43 | + } |
| 44 | + |
| 45 | + public function configureOptions(OptionsResolver $resolver): void |
| 46 | + { |
| 47 | + $choices = []; |
| 48 | + foreach ($this->preferred_languages as $lang_code) { |
| 49 | + $choices[Languages::getName($lang_code)] = $lang_code; |
| 50 | + } |
| 51 | + |
| 52 | + $resolver->setDefaults([ |
| 53 | + 'choice_loader' => null, |
| 54 | + 'choices' => $choices, |
| 55 | + ]); |
| 56 | + } |
| 57 | +} |
0 commit comments