ActionAdmin.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace WorkflowBundle\Admin;
  3. use Base\AdminBundle\Admin\BaseAdmin;
  4. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Form\FormMapper;
  7. use Sonata\AdminBundle\Show\ShowMapper;
  8. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use WorkflowBundle\Utils\WorkFlowEntityClasses;
  11. use WorkflowBundle\Utils\WorkFlowEvents;
  12. use WorkflowBundle\Utils\DoctrineEvents;
  13. class ActionAdmin extends BaseAdmin
  14. {
  15. public function getTemplate($name)
  16. {
  17. switch ($name) {
  18. case 'edit':
  19. return 'WorkflowBundle:Action:action_edit.html.twig';
  20. break;
  21. default:
  22. return parent::getTemplate($name);
  23. break;
  24. }
  25. }
  26. /**
  27. * @param DatagridMapper $datagridMapper
  28. */
  29. protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  30. {
  31. $datagridMapper
  32. ->add('name')
  33. ->add('workflowName')
  34. ->add('objectClass')
  35. ->add('event')
  36. ;
  37. }
  38. /**
  39. * @param ListMapper $listMapper
  40. */
  41. protected function configureListFields(ListMapper $listMapper)
  42. {
  43. $listMapper
  44. ->add('name')
  45. ->add('workflowName')
  46. ->add('objectClass')
  47. ->add('event', 'html', array(
  48. 'template' => 'BaseAdminBundle:Utils:badge_field.html.twig',
  49. ))
  50. ->add('eventReference')
  51. ->add('_action', null, array(
  52. 'actions' => array(
  53. 'show' => array(),
  54. 'edit' => array(),
  55. 'delete' => array(),
  56. )
  57. ))
  58. ;
  59. }
  60. /**
  61. * @param FormMapper $formMapper
  62. */
  63. protected function configureFormFields(FormMapper $formMapper)
  64. {
  65. $formMapper
  66. ->add('name')
  67. ->add('event', ChoiceType::class, array(
  68. 'choices' => array(
  69. 'WorkFlow' => WorkFlowEvents::getChoices(),
  70. 'Doctrine' => DoctrineEvents::getDoctrineEventChoices(),
  71. ),
  72. 'required' => false,
  73. 'multiple' => true,
  74. )
  75. )
  76. ->add('workflowName', TextType::class, array(
  77. 'required' => false,
  78. ))
  79. ->add('eventReference', TextType::class, array(
  80. 'required' => false,
  81. ))
  82. ->add('objectClass', ChoiceType::class, array(
  83. 'choices' => array_filter(WorkFlowEntityClasses::getChoices(), 'class_exists'),
  84. 'required' => false,
  85. )
  86. )
  87. ->add('template', null, array(
  88. 'attr' => array(
  89. 'style' => 'height:500px;',
  90. ),
  91. )
  92. )
  93. ->setHelps(array(
  94. 'workflowName' => $this->trans("helps.action_label_workflow_name"),
  95. 'name' => $this->trans("helps.action_label_name"),
  96. 'objectClass' => $this->trans("helps.action_label_object_class"),
  97. 'event' => $this->trans("helps.action_label_event"),
  98. 'eventReference' => $this->trans("helps.action_label_event_reference"),
  99. 'template' => $this->trans("helps.action_label_template"),
  100. )
  101. )
  102. ;
  103. }
  104. /**
  105. * @param ShowMapper $showMapper
  106. */
  107. protected function configureShowFields(ShowMapper $showMapper)
  108. {
  109. $showMapper
  110. ->add('id')
  111. ->add('name')
  112. ->add('workflowName')
  113. ->add('objectClass')
  114. ->add('event', 'string', array(
  115. 'template' => 'BaseAdminBundle:Utils:badge_field.html.twig',
  116. ))
  117. ->add('eventReference')
  118. ->add('template','string', array(
  119. 'template' => 'WorkflowBundle:Action:show_template.html.twig',
  120. ))
  121. ;
  122. $this->parameters = array(
  123. 'template_type' => 'show',
  124. );
  125. }
  126. }