WorkflowAdmin.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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\Yaml\Yaml;
  10. use WorkflowBundle\Utils\WorkFlowEntityClasses;
  11. class WorkflowAdmin extends BaseAdmin
  12. {
  13. public function getTemplate($name)
  14. {
  15. switch ($name) {
  16. case 'edit':
  17. return 'WorkflowBundle:Workflow:workflow_edit.html.twig';
  18. break;
  19. default:
  20. return parent::getTemplate($name);
  21. break;
  22. }
  23. }
  24. /**
  25. * @param DatagridMapper $datagridMapper
  26. */
  27. protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  28. {
  29. $datagridMapper
  30. ->add('name')
  31. ->add('description')
  32. ->add('enable')
  33. ->add('template')
  34. ;
  35. }
  36. /**
  37. * @param ListMapper $listMapper
  38. */
  39. protected function configureListFields(ListMapper $listMapper)
  40. {
  41. $listMapper
  42. ->add('name')
  43. ->add('description')
  44. ->add('enable')
  45. ->add('usedByDefault')
  46. ->add('_action', null, array(
  47. 'actions' => array(
  48. 'show' => array(),
  49. 'edit' => array(),
  50. 'delete' => array()
  51. )
  52. ));
  53. }
  54. /**
  55. * @param FormMapper $formMapper
  56. */
  57. protected function configureFormFields(FormMapper $formMapper)
  58. {
  59. $template_example =
  60. "
  61. initial_place: state_two
  62. places:
  63. - state_one
  64. - state_two
  65. - state_three
  66. transitions:
  67. one_to_two:
  68. from: state_one
  69. to: state_two
  70. two_to_three:
  71. from: state_two
  72. to: state_three
  73. two_to_one:
  74. from: state_two
  75. to: state_one
  76. three_to_one:
  77. from: state_three
  78. to: state_one
  79. ";
  80. // Create => template_example
  81. $tempate_options = array(
  82. "attr" => array(
  83. 'style' => 'height:500px;',
  84. ),
  85. );
  86. if (is_null($this->getSubject()->getId())) {
  87. $tempate_options['data'] = $template_example;
  88. } else {
  89. $this->parameters = array(
  90. 'workflow_name' => $this->getSubject()->getName(),
  91. 'workflow_subject' => $this->getSubject()->getSubject());
  92. }
  93. $formMapper
  94. ->add('name')
  95. ->add('description')
  96. ->add('enable')
  97. ->add('usedByDefault')
  98. ->add('type', ChoiceType::class, array(
  99. 'choices' => array(
  100. 'state_machine' => 'state_machine',
  101. 'workflow' => 'workflow',
  102. )))
  103. ->add('markingType', ChoiceType::class, array(
  104. 'choices' => array(
  105. 'single_state' => 'single_state',
  106. 'multiple_state' => 'multiple_state',
  107. )))
  108. ->add('markingName', ChoiceType::class, array(
  109. 'choices' => array(
  110. 'currentState' => 'currentState',
  111. )))
  112. ->add('support', ChoiceType::class, array(
  113. 'choices' => array_filter(WorkFlowEntityClasses::getChoices(), 'class_exists'),
  114. 'multiple' => true,
  115. 'required' => true,
  116. ))
  117. ->add('template', null, $tempate_options)
  118. ->setHelps(array(
  119. 'name' => $this->trans("helps.workflow_label_name"),
  120. 'type' => $this->trans("helps.workflow_label_type"),
  121. 'markingType' => $this->trans("helps.workflow_label_marking_type"),
  122. 'markingName' => $this->trans("helps.workflow_label_marking_name"),
  123. 'template' => $this->trans("helps.workflow_label_template"),
  124. ));
  125. }
  126. /**
  127. * @param ShowMapper $showMapper
  128. */
  129. protected function configureShowFields(ShowMapper $showMapper)
  130. {
  131. $showMapper
  132. ->add('id')
  133. ->add('name')
  134. ->add('description')
  135. ->add('enable')
  136. ->add('usedByDefault')
  137. ->add('created')
  138. ->add('updated')
  139. ->add('type')
  140. ->add('markingType')
  141. ->add('markingName')
  142. ->add('support')
  143. ->add('template','string', array(
  144. 'template' => 'WorkflowBundle:Workflow:show_template.html.twig'
  145. ));
  146. }
  147. }