Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

92 lines
2.7KB

  1. <?php
  2. namespace Lc\PietroBundle\Form\Dream;
  3. use Lc\PietroBundle\Model\Dream;
  4. use Lc\PietroBundle\Model\Subthematic;
  5. use Lc\PietroBundle\Model\Thematic;
  6. use Lc\SovBundle\Doctrine\EntityManager;
  7. use Lc\SovBundle\Translation\TranslatorAdmin;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\OptionsResolver\OptionsResolver;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class DreamType extends AbstractType
  15. {
  16. protected $em;
  17. protected $translatorAdmin;
  18. public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin)
  19. {
  20. $this->em = $em;
  21. $this->translatorAdmin = $translatorAdmin;
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function buildForm(FormBuilderInterface $builder, array $options)
  27. {
  28. $builder->add(
  29. 'description',
  30. TextareaType::class,
  31. [
  32. 'label' => 'form.field.dream.description',
  33. 'constraints' => [
  34. new NotBlank(),
  35. ],
  36. ]
  37. )
  38. ->add(
  39. 'thematic',
  40. EntityType::class,
  41. [
  42. 'label' => 'form.field.dream.thematic',
  43. 'class' => Thematic::class,
  44. 'required' => false,
  45. 'choice_attr' => function ($choice, $key, $value) {
  46. return ['data-class' => 'theme' . strtolower($value)];
  47. },
  48. 'attr' => [
  49. 'class' => 'theme'
  50. ]
  51. ]
  52. );
  53. if ($options['context'] == "backend") {
  54. $builder->add(
  55. 'subthematic',
  56. EntityType::class,
  57. [
  58. 'label' => 'form.field.dream.subthematic',
  59. 'class' => Subthematic::class,
  60. 'required' => false,
  61. 'choice_attr' => function ($choice, $key, $value) {
  62. return ['data-class' => 'theme' . strtolower($choice->getThematic()->getId())];
  63. },
  64. 'attr' => [
  65. 'class' => 'subtheme'
  66. ]
  67. ]
  68. );
  69. }
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function configureOptions(OptionsResolver $resolver)
  75. {
  76. $resolver->setDefaults(
  77. [
  78. 'data_class' => $this->em->getEntityName(Dream::class),
  79. 'context' => 'backend'
  80. ]
  81. );
  82. }
  83. }