workflowRegistry = $workflowRegistry; } public function getFunctions() { return array( new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')), new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')), new \Twig_SimpleFunction('workflow_correct_state', array($this, 'isCorrectState')), new \Twig_SimpleFunction('get_class', array($this, 'getClass')) ); } public function isCorrectState($object, $name = null) { try { $places = $this->workflowRegistry->get($object, $name)->getDefinition()->getPlaces(); } catch (\Exception $e) { $places = array(); } $state = $object->getCurrentState(); if(is_null($state)) return false; if(isset($places[$state])) return true; return false; } public function canTransition($object, $transition, $name = null) { return $this->workflowRegistry->get($object, $name)->can($object, $transition); } public function getEnabledTransitions($object, $name = null) { try { $return = $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object); } catch (\Exception $e) { $return = array(); } return $return; } public function getName() { return 'workflow'; } public function getClass($object) { return get_class($object); } }