|
- <?php
-
- namespace Lc\PietroBundle\Form\Dream;
-
- use Lc\PietroBundle\Model\Dream\DreamInterface;
- use Lc\PietroBundle\Model\Subthematic\SubthematicInterface;
- use Lc\PietroBundle\Model\Thematic\ThematicInterface;
- 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)
- {
- $placeholder = "";
- if (isset($options['placeholder_description'])) {
- $placeholder = $options['placeholder_description'];
- }
-
- $builder->add(
- 'description',
- TextareaType::class,
- [
- 'label' => 'form.field.dream.description',
- 'constraints' => [
- new NotBlank(),
- ],
- 'attr' => [
- "placeholder" => $placeholder
- ]
- ]
- );
- if ($options['thematic'] == true) {
- $builder->add(
- 'thematic',
- EntityType::class,
- [
- 'label' => 'form.field.dream.thematic',
- 'class' => $this->em->getEntityName(ThematicInterface::class),
- 'required' => false,
- 'choice_attr' => function ($choice, $key, $value) {
- return ['data-class' => 'theme' . strtolower($value)];
- },
- 'attr' => [
- 'class' => 'theme'
- ]
- ]
- );
- }
- if ($options['context'] == "backend" && $options['thematic'] == true) {
- $builder->add(
- 'subthematic',
- EntityType::class,
- [
- 'label' => 'form.field.dream.subthematic',
- 'class' => $this->em->getEntityName(SubthematicInterface::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(DreamInterface::class),
- 'context' => 'backend',
- 'thematic' => true,
- 'placeholder_description' => false
- ]
- );
- }
- }
|