diff --git a/src/bundle/Resources/config/services/forms.yaml b/src/bundle/Resources/config/services/forms.yaml index a6f0893fec..bdd11af7d7 100644 --- a/src/bundle/Resources/config/services/forms.yaml +++ b/src/bundle/Resources/config/services/forms.yaml @@ -415,3 +415,5 @@ services: arguments: $siteAccessResolver: '@Ibexa\AdminUi\Siteaccess\NonAdminSiteaccessResolver' $siteAccessNameGenerator: '@Ibexa\AdminUi\Siteaccess\SiteAccessNameGenerator' + + Ibexa\AdminUi\Form\Type\LanguageSwitchType: ~ diff --git a/src/lib/Form/Data/AbstractLanguageSwitchData.php b/src/lib/Form/Data/AbstractLanguageSwitchData.php new file mode 100644 index 0000000000..4901b9c922 --- /dev/null +++ b/src/lib/Form/Data/AbstractLanguageSwitchData.php @@ -0,0 +1,31 @@ +language = $language; + } + + public function getLanguage(): ?Language + { + return $this->language; + } + + public function setLanguage(?Language $language): void + { + $this->language = $language; + } +} diff --git a/src/lib/Form/Type/LanguageSwitchType.php b/src/lib/Form/Type/LanguageSwitchType.php new file mode 100644 index 0000000000..f59b669956 --- /dev/null +++ b/src/lib/Form/Type/LanguageSwitchType.php @@ -0,0 +1,58 @@ +languageService = $languageService; + } + + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $languages = $options['languages']; + + $builder->add( + 'language', + ConfiguredLanguagesChoiceType::class, + [ + 'choice_loader' => ChoiceList::lazy( + $this, + function () use ($languages): iterable { + return $this->languageService->loadLanguageListByCode($languages); + }, + $languages + ), + ] + ); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'csrf_protection' => false, + 'data_class' => AbstractLanguageSwitchData::class, + 'method' => Request::METHOD_GET, + ]); + + $resolver->setRequired('languages'); + } +}