|
- <?php
-
- namespace Lc\PietroBundle\Form\Dream;
-
- use Lc\PietroBundle\Model\Dream;
- use Lc\PietroBundle\Model\Subthematic;
- use Lc\PietroBundle\Model\Thematic;
- use Lc\SovBundle\Doctrine\EntityManager;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Bridge\Doctrine\Form\Type\EntityType;
- use Symfony\Component\Form\AbstractType;
- use Symfony\Component\Form\Extension\Core\Type\TextareaType;
- use Symfony\Component\Form\FormBuilderInterface;
- use Symfony\Component\OptionsResolver\OptionsResolver;
- use Symfony\Component\Validator\Constraints\NotBlank;
-
- class DreamType extends AbstractType
- {
-
- protected $em;
- protected $translatorAdmin;
-
- public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin)
- {
- $this->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'
- ]
- );
- }
- }
|