src/Form/EventSubscriber/Quote/AddAttributeValueSubscriber.php line 33
<?phpnamespace App\Form\EventSubscriber\Quote;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Form\Extension\Core\Type\ChoiceType;use Symfony\Component\Form\Extension\Core\Type\TextType;use Symfony\Component\Form\FormEvent;use Symfony\Component\Form\FormEvents;use Sylius\Component\Locale\Context\LocaleContextInterface;use Symfony\Component\HttpFoundation\RequestStack;class AddAttributeValueSubscriber implements EventSubscriberInterface{public $request;private $contextLocale;public function __construct(RequestStack $request, LocaleContextInterface $localeContext){$this->request = $request->getCurrentRequest();$this->contextLocale = $localeContext;}public static function getSubscribedEvents(){// Tells the dispatcher that you want to listen on the form.pre_set_data// event and that the preSetData method should be called.return [FormEvents::PRE_SET_DATA => 'preSetData'];}public function preSetData(FormEvent $event){dd($this->contextLocale->getLocaleCode());$data = $event->getData();$attribute = $data->getAttribute();$configuration = $attribute->getConfiguration();switch ($attribute->getType()) {case 'select':$type = ChoiceType::class;$optionConf = $this->buildFormOptions($attribute);break;default:$type = TextType::class;$optionConf = $attribute->getConfiguration();break;}$form = $event->getForm();$form->add('value', $type, $optionConf);}private function buildFormOptions($attribute){$optionConf = $attribute->getConfiguration();$choices = [];foreach ($optionConf['choices'] as $value) {foreach ($value as $ele) {$choices[] = $ele;}}//dd(array_($choices));$optionConf['choices'] = $choices;return array('choices' => $choices,'multiple' => $optionConf['multiple'],'expanded' => false,'required' => true);}}