Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

105 lines
3.3KB

  1. <?php
  2. namespace Lc\PietroBundle\Form\ProjectInspiring;
  3. use Lc\PietroBundle\Model\ProjectInspiring\ProjectInspiringInterface;
  4. use Lc\PietroBundle\Model\Subthematic\SubthematicInterface;
  5. use Lc\PietroBundle\Model\Thematic\ThematicInterface;
  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 ProjectInspiringType 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. $placeholder = "";
  29. if (isset($options['placeholder_description'])) {
  30. $placeholder = $options['placeholder_description'];
  31. }
  32. $builder->add(
  33. 'description',
  34. TextareaType::class,
  35. [
  36. 'label' => 'form.field.projectinspiring.description',
  37. 'constraints' => [
  38. new NotBlank(),
  39. ],
  40. 'attr' => [
  41. "placeholder" => $placeholder
  42. ]
  43. ]
  44. );
  45. if ($options['thematic'] == true) {
  46. $builder->add(
  47. 'thematic',
  48. EntityType::class,
  49. [
  50. 'label' => 'form.field.projectinspiring.thematic',
  51. 'class' => $this->em->getEntityName(ThematicInterface::class),
  52. 'required' => false,
  53. 'choice_attr' => function ($choice, $key, $value) {
  54. return ['data-class' => 'theme' . strtolower($value)];
  55. },
  56. 'attr' => [
  57. 'class' => 'theme'
  58. ]
  59. ]
  60. );
  61. }
  62. if ($options['context'] == "backend" && $options['thematic'] == true) {
  63. $builder->add(
  64. 'subthematic',
  65. EntityType::class,
  66. [
  67. 'label' => 'form.field.projectinspiring.subthematic',
  68. 'class' => $this->em->getEntityName(SubthematicInterface::class),
  69. 'required' => false,
  70. 'choice_attr' => function ($choice, $key, $value) {
  71. return ['data-class' => 'theme' . strtolower($choice->getThematic()->getId())];
  72. },
  73. 'attr' => [
  74. 'class' => 'subtheme'
  75. ]
  76. ]
  77. );
  78. }
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function configureOptions(OptionsResolver $resolver)
  84. {
  85. $resolver->setDefaults(
  86. [
  87. 'data_class' => $this->em->getEntityName(ProjectInspiringInterface::class),
  88. 'context' => 'backend',
  89. 'thematic' => true,
  90. 'placeholder_description' => false
  91. ]
  92. );
  93. }
  94. }