123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace WorkflowBundle\Admin;
- use Base\AdminBundle\Admin\BaseAdmin;
- use Sonata\AdminBundle\Datagrid\DatagridMapper;
- use Sonata\AdminBundle\Datagrid\ListMapper;
- use Sonata\AdminBundle\Form\FormMapper;
- use Sonata\AdminBundle\Show\ShowMapper;
- use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
- use Symfony\Component\Yaml\Yaml;
- use WorkflowBundle\Utils\WorkFlowEntityClasses;
- class WorkflowAdmin extends BaseAdmin
- {
- public function getTemplate($name)
- {
- switch ($name) {
- case 'edit':
- return 'WorkflowBundle:Workflow:workflow_edit.html.twig';
- break;
- default:
- return parent::getTemplate($name);
- break;
- }
- }
- /**
- * @param DatagridMapper $datagridMapper
- */
- protected function configureDatagridFilters(DatagridMapper $datagridMapper)
- {
- $datagridMapper
- ->add('name')
- ->add('description')
- ->add('enable')
- ->add('template')
- ;
- }
- /**
- * @param ListMapper $listMapper
- */
- protected function configureListFields(ListMapper $listMapper)
- {
- $listMapper
- ->add('name')
- ->add('description')
- ->add('enable')
- ->add('usedByDefault')
- ->add('_action', null, array(
- 'actions' => array(
- 'show' => array(),
- 'edit' => array(),
- 'delete' => array()
- )
- ));
- }
- /**
- * @param FormMapper $formMapper
- */
- protected function configureFormFields(FormMapper $formMapper)
- {
- $template_example =
- "
- initial_place: state_two
- places:
- - state_one
- - state_two
- - state_three
- transitions:
- one_to_two:
- from: state_one
- to: state_two
- two_to_three:
- from: state_two
- to: state_three
- two_to_one:
- from: state_two
- to: state_one
- three_to_one:
- from: state_three
- to: state_one
- ";
- // Create => template_example
- $tempate_options = array(
- "attr" => array(
- 'style' => 'height:500px;',
- ),
- );
- if (is_null($this->getSubject()->getId())) {
- $tempate_options['data'] = $template_example;
- } else {
- $this->parameters = array(
- 'workflow_name' => $this->getSubject()->getName(),
- 'workflow_subject' => $this->getSubject()->getSubject());
- }
-
- $formMapper
- ->add('name')
- ->add('description')
- ->add('enable')
- ->add('usedByDefault')
- ->add('type', ChoiceType::class, array(
- 'choices' => array(
- 'state_machine' => 'state_machine',
- 'workflow' => 'workflow',
- )))
- ->add('markingType', ChoiceType::class, array(
- 'choices' => array(
- 'single_state' => 'single_state',
- 'multiple_state' => 'multiple_state',
- )))
- ->add('markingName', ChoiceType::class, array(
- 'choices' => array(
- 'currentState' => 'currentState',
- )))
- ->add('support', ChoiceType::class, array(
- 'choices' => array_filter(WorkFlowEntityClasses::getChoices(), 'class_exists'),
- 'multiple' => true,
- 'required' => true,
- ))
- ->add('template', null, $tempate_options)
- ->setHelps(array(
- 'name' => $this->trans("helps.workflow_label_name"),
- 'type' => $this->trans("helps.workflow_label_type"),
- 'markingType' => $this->trans("helps.workflow_label_marking_type"),
- 'markingName' => $this->trans("helps.workflow_label_marking_name"),
- 'template' => $this->trans("helps.workflow_label_template"),
- ));
- }
- /**
- * @param ShowMapper $showMapper
- */
- protected function configureShowFields(ShowMapper $showMapper)
- {
- $showMapper
- ->add('id')
- ->add('name')
- ->add('description')
- ->add('enable')
- ->add('usedByDefault')
- ->add('created')
- ->add('updated')
- ->add('type')
- ->add('markingType')
- ->add('markingName')
- ->add('support')
- ->add('template','string', array(
- 'template' => 'WorkflowBundle:Workflow:show_template.html.twig'
- ));
- }
- }
|