A2LiX Перевод на вкладке изменения языка получить язык в форме

Мне нужен язык для изменения вкладок A2LiX Translation. Если я нажимаю на «FR», то нужно получить Fr, а на «NL» нужен язык Nl в конструкторе форм («Need Language Here»).

Для построителя запросов в одном поле.
Можно ли получить язык в форме при смене вкладки?

введите описание изображения здесь

Моя форма класса MixCampaignTranslationType:

<?php

namespace BackEndBundle\Form;

use BackEndBundle\Validator\Constraints\CampaignSlugDuplicate;
use BackEndBundle\Validator\Constraints\MaxMixCampaign;
use Doctrine\ORM\EntityRepository;
use SurveyBundle\Entity\Survey;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Type;

class MixCampaignTranslationType extends AbstractType
{
public $campaignId = null;

public function buildForm(FormBuilderInterface $builder, array $options)
{
if (null !== $options['campaignId']) {
$this->campaignId = $options['campaignId'];
}

$builder
->add('surveys', EntityType::class, [
'class'    => Survey::class,
'required' => false,
'multiple' => true,
'mapped'   => true,
'attr'     => [
'class' => 'select2',
],
'constraints' => new MaxMixCampaign(),
])
->add('startDate', DateTimeType::class, [
'widget'      => 'single_text',
'format'      => 'yyyy-MM-dd',
'constraints' => new NotBlank(),
'attr'        => [
'class' => 'datepicker',
],
])
->add('endDate', DateTimeType::class, [
'widget'      => 'single_text',
'format'      => 'yyyy-MM-dd',
'constraints' => new NotBlank(),
'attr'        => [
'class' => 'datepicker',
],
])
->add('slug', TextType::class, [
'constraints' => [new NotBlank(), new Type('string'), new CampaignSlugDuplicate($this->campaignId, $options['locale'], 'mix')],
])
->add('isClosed');
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'SurveyBundle\Entity\MixCampaignTranslation',
'locale'     => 'fr',
'campaignId' => null
]);
}

public function getName()
{
return 'back_end_bundle_mix_campaign_translation_type';
}
}

2

Решение

Вы можете создать свой собственный TranslationFormType и затем передать язык цикла в качестве текущего языка. Пожалуйста, проверьте, как показано ниже.

/**
* @param \Symfony\Component\Form\FormBuilderInterface $builder
* @param array                                        $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventSubscriber($this->translationsListener);
$formsOptions = $this->translationForm->getFormsOptions($options);
foreach ($options['locales'] as $locale) {
if (isset($formsOptions[$locale])) {
$builder->add($locale, $options['form_type'], [
'currentLanguage' => $locale,
'campaignId' => $formsOptions[$locale]['campaignId']
]
);
}
}
}

и вы можете использовать currentLanguage для фильтрации данных в query_builder в вашем form_type,

Надеюсь, это поможет вам.

2

Другие решения

Других решений пока нет …