checkRole('ROLE_SONATA_WORKFLOW_ADMIN') || $this->checkRole('ROLE_SONATA_WORKFLOW_EDITOR') || $this->checkRole('ROLE_SUPER_ADMIN'))) { return $actions; } asort($actions); $actionsBase = []; $actionsBase['Default'] = array( 'label' => $this->trans('Default', array(), 'WorkflowLabel'), 'group' => $actions ); $actions = []; $workflows = array(); $registry = $this->get('workflow.registry'); $class = $this->getClass(); $tmpEntity = new $class(); try { $workflows = $this->getRepository('WorkflowBundle:Workflow')->findAllByClass($this->getClass()); // No hay workflows en db, pruebo traer desde el workflow registry if (count($workflows) == 0) { $workflows[] = $registry->get($tmpEntity); } $actions += $this->addActions($workflows, 'Entity'); } catch (\Exception $ex) { } if (isset($this->batchWorkflows)) { // No hay workflows en db, pruebo traer desde el workflow registry // con los names definidos en el admin $batchWorkflows foreach ($this->batchWorkflows as $name) { $workflows[] = $registry->get($tmpEntity, $name); } $actions += $this->addActions($workflows, 'File'); } asort($actions); return $actionsBase + $actions; } private function addActions($workflows, $place) { foreach ($workflows as $workflow) { $definition = method_exists($workflow, 'getSubject') ? $workflow->getDefinition($workflow->getSubject()) : $workflow->getDefinition(); $transitions = $definition ? $definition->getTransitions() : array(); $tmp = array(); foreach ($transitions as $transition) { $id = 'workflow.' . $workflow->getName() . '.transitions.' . $transition->getName(); $label = $this->trans($id, array(), 'WorkflowLabel'); if ($label == $id) { $label = $transition->getName(); } $label .= " ( {$transition->getName()} )"; $tmp["workflow:" . $workflow->getName() . ':' . $transition->getName()] = array( 'label' => $label, 'ask_confirmation' => true, 'workflow' => array( 'name' => $workflow->getName(), 'transition' => $transition->getName(), ), ); } asort($tmp); $actions[$workflow->getName()] = array( 'label' => $this->trans($workflow->getName(), array(), 'WorkflowLabel'), 'group' => $tmp ); } return $actions; } }