|
@@ -14,13 +14,36 @@ class WorkflowBaseAdmin extends BaseAdmin
|
|
|
{
|
|
|
$actions = parent::getBatchActions();
|
|
|
|
|
|
- $workflows = $this->getRepository('WorkflowBundle:Workflow')->findAllByClass($this->getClass());
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+ } catch (\Exception $ex) {
|
|
|
+ // No hay workflows en db, pruebo traer desde el workflow registry
|
|
|
+ // con los names definidos en el admin $batchWorkflows
|
|
|
+ if (isset($this->batchWorkflows)) {
|
|
|
+ foreach ($this->batchWorkflows as $name) {
|
|
|
+ $workflows[] = $registry->get($tmpEntity, $name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($workflows as $workflow) {
|
|
|
- $definition = $workflow->getDefinition($workflow->getSubject());
|
|
|
+ $definition = method_exists($workflow, 'getSubject')
|
|
|
+ ? $workflow->getDefinition($workflow->getSubject())
|
|
|
+ : $workflow->getDefinition();
|
|
|
$transitions = $definition ? $definition->getTransitions() : array();
|
|
|
- foreach ($transitions as $key => $transition) {
|
|
|
- $actions[$key] = array(
|
|
|
- 'label' => $this->trans('workflow.' . $workflow->getName() . '.transitions.' . $transition->getName(), array(), 'WorkflowLabel'),
|
|
|
+ foreach ($transitions as $transition) {
|
|
|
+ $label = $this->trans('workflow.' . $workflow->getName() . '.transitions.' . $transition->getName(), array(), 'WorkflowLabel');
|
|
|
+ $label .= " ( {$transition->getName()} )";
|
|
|
+ $actions[$transition->getName()] = array(
|
|
|
+ 'label' => $label,
|
|
|
'ask_confirmation' => true,
|
|
|
'workflow' => array(
|
|
|
'name' => $workflow->getName(),
|
|
@@ -29,7 +52,8 @@ class WorkflowBaseAdmin extends BaseAdmin
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ asort($actions);
|
|
|
+
|
|
|
return $actions;
|
|
|
}
|
|
|
|