src/Transformer/JsonSchemaForm/ChoiceTransformer.php line 29
<?phpdeclare(strict_types=1);/*** Copyright (c) 2019 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2019 TECLA Consulting Group oü*/namespace App\Transformer\JsonSchemaForm;use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;use Symfony\Component\Form\FormInterface;class ChoiceTransformer extends AbstractTransformer{/*** {@inheritdoc}*/public function transform(FormInterface $form, array $extensions = [], string $widget = null): array{$formView = $form->createView();$translationDomain = $form->getConfig()->getOption('translation_domain');$choices = [];$titles = [];foreach ($formView->vars['choices'] as $choiceView) {if (true === $choiceView instanceof ChoiceGroupView) {foreach ($choiceView->choices as $choiceItem) {$title = $choiceItem->label;if (false !== $translationDomain) {$title = $this->translator->trans($title);}$choices[] = $choiceItem->value;$titles[] = $title;}} else {$title = $choiceView->label;if (false !== $translationDomain) {$title = $this->translator->trans($title);}$choices[] = $choiceView->value;$titles[] = $title;}}if ($formView->vars['multiple']) {$schema = $this->transformMultiple($form, $choices, $titles);} else {$schema = $this->transformSingle($form, $choices, $titles);}$schema = $this->addCommonSpecs($form, $schema, $widget, $extensions);return $schema;}private function transformSingle(FormInterface $form, array $choices, array $titles): array{$formView = $form->createView();$schema = ['enum' => $choices,'enum_titles' => $titles,'type' => 'string',];if ($formView->vars['expanded']) {$schema['widget'] = 'choice-expanded';}return $schema;}private function transformMultiple(FormInterface $form, array $choices, array $titles): array{$formView = $form->createView();$schema = ['items' => ['type' => 'string','enum' => $choices,'enum_titles' => $titles,],'minItems' => true === $this->isRequired($form) ? 1 : 0,'uniqueItems' => true,'type' => 'array',];if (true === $formView->vars['expanded']) {$schema['widget'] = 'choice-multiple-expanded';}return $schema;}}