em = $em; $this->translatorAdmin = $translatorAdmin; } /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add( 'description', TextareaType::class, [ 'label' => 'form.field.dream.description', 'constraints' => [ new NotBlank(), ], ] ) ->add( 'thematic', EntityType::class, [ 'label' => 'form.field.dream.thematic', 'class' => Thematic::class, 'required' => false, 'choice_attr' => function ($choice, $key, $value) { return ['data-class' => 'theme' . strtolower($value)]; }, 'attr' => [ 'class' => 'theme' ] ] ); if ($options['context'] == "backend") { $builder->add( 'subthematic', EntityType::class, [ 'label' => 'form.field.dream.subthematic', 'class' => Subthematic::class, 'required' => false, 'choice_attr' => function ($choice, $key, $value) { return ['data-class' => 'theme' . strtolower($choice->getThematic()->getId())]; }, 'attr' => [ 'class' => 'subtheme' ] ] ); } } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( [ 'data_class' => $this->em->getEntityName(Dream::class), 'context' => 'backend' ] ); } }