Created
December 2, 2020 22:40
-
-
Save kurozumi/195b5b913eba2e1fa5c0168853a0b062 to your computer and use it in GitHub Desktop.
アンケートのフォームタイプ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Customize\Form; | |
use Customize\Entity\Questionnaire; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
class CreateQuestionnaire extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
switch ($options['flow_step']) { | |
case 1: | |
$builder->add('q1', ChoiceType::class, [ | |
'choices' => ["男性" => "男性", "女性" => "女性", "その他" => "その他"], | |
'expanded' => true, | |
'multiple' => false | |
]); | |
break; | |
case 2: | |
$values = array_map(function ($age) { | |
return $age."代"; | |
}, range(10, 90, 10)); | |
$builder->add('q2', ChoiceType::class, [ | |
'choices' => array_combine($values, $values) + ["それ以上" => "それ以上"], | |
'placeholder' => 'common.select' | |
]); | |
break; | |
case 3: | |
$builder->add('q3', TextareaType::class, [ | |
'required' => false | |
]); | |
break; | |
} | |
} | |
/** | |
* @param OptionsResolver $resolver | |
*/ | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults([ | |
'data_class' => Questionnaire::class | |
]); | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getBlockPrefix() | |
{ | |
return 'createQuestionnaire'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment