Browse Source

try/catch cuando no hay definición de workflow

iksop 7 years ago
parent
commit
d1a52302c4
1 changed files with 6 additions and 1 deletions
  1. 6 1
      Twig/WorkflowExtension.php

+ 6 - 1
Twig/WorkflowExtension.php

@@ -1,10 +1,11 @@
 <?php
-
 namespace WorkflowBundle\Twig;
 
 use Symfony\Component\Workflow\Registry;
 use Symfony\Component\Translation\TranslatorInterface;
 
+use Symfony\Component\Workflow\Exception\InvalidArgumentException;
+
 class WorkflowExtension extends \Twig_Extension
 {
     private $workflowRegistry;
@@ -90,7 +91,11 @@ class WorkflowExtension extends \Twig_Extension
         $nodes = array();
         $links = array();
 
+       try{
         $definition = $this->workflowRegistry->get($object, $name)->getDefinition();
+       }catch (InvalidArgumentException $e){
+          return json_encode(array());
+        }
         $places = $definition->getPlaces();
         $initial = $definition->getInitialPlace();
         $transitions = $definition->getTransitions();