You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.8KB

  1. <?php
  2. namespace Lc\SovBundle\Form\Ticket;
  3. use Lc\SovBundle\Doctrine\EntityManager;
  4. use Lc\SovBundle\Model\Ticket\TicketInterface;
  5. use Lc\SovBundle\Model\Ticket\TicketModel;
  6. use Lc\SovBundle\Model\User\UserInterface;
  7. use Lc\SovBundle\Solver\Ticket\TicketSolver;
  8. use Lc\SovBundle\Translation\TranslatorAdmin;
  9. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  10. use Symfony\Component\Form\AbstractType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  13. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  14. use Symfony\Component\Form\Extension\Core\Type\TextType;
  15. use Symfony\Component\Form\FormBuilderInterface;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. class TicketFormType extends AbstractType
  18. {
  19. protected EntityManager $entityManager;
  20. protected TranslatorAdmin $translatorAdmin;
  21. public function __construct(
  22. EntityManager $entityManager,
  23. TranslatorAdmin $translatorAdmin
  24. ) {
  25. $this->entityManager = $entityManager;
  26. $this->translatorAdmin = $translatorAdmin;
  27. }
  28. public function buildForm(FormBuilderInterface $builder, array $options)
  29. {
  30. $entityName = $this->entityManager->getEntityName(TicketInterface::class);
  31. $builder->add(
  32. 'user',
  33. EntityType::class,
  34. [
  35. 'class' => $this->entityManager->getEntityName(UserInterface::class),
  36. ]
  37. );
  38. $builder->add(
  39. 'type',
  40. ChoiceType::class,
  41. [
  42. 'label' => 'Type',
  43. 'choices' => $this->translatorAdmin->transChoices(
  44. TicketSolver::getTypeChoices(),
  45. 'Ticket',
  46. 'type'
  47. ),
  48. ]
  49. );
  50. $builder->add(
  51. 'subject',
  52. TextType::class
  53. );
  54. $builder->add(
  55. 'ticketMessages',
  56. CollectionType::class,
  57. [
  58. 'entry_type' => TicketMessageType::class,
  59. 'allow_add' => false,
  60. 'label_attr' => ['class' => 'label-ticket'],
  61. ]
  62. );
  63. $builder->add(
  64. 'submit',
  65. SubmitType::class,
  66. [
  67. 'label' => $this->translatorAdmin->transAction('save')
  68. ]
  69. );
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function configureOptions(OptionsResolver $resolver)
  75. {
  76. $resolver->setDefaults(
  77. [
  78. 'data_class' => $this->entityManager->getEntityName(TicketInterface::class),
  79. ]
  80. );
  81. }
  82. }