Bläddra i källkod

[Form] Fix the exception message when no block is found while rendering

Victor Berchet 14 år sedan
förälder
incheckning
da467a6b11

+ 7 - 4
src/Symfony/Bridge/Twig/Extension/FormExtension.php

@@ -251,13 +251,13 @@ class FormExtension extends \Twig_Extension
         }
 
         do {
-            $block = $types[$typeIndex].'_'.$section;
+            $types[$typeIndex] .= '_'.$section;
 
-            if (isset($blocks[$block])) {
+            if (isset($blocks[$types[$typeIndex]])) {
 
                 $this->varStack[$rendering]['typeIndex'] = $typeIndex;
 
-                $html = $this->template->renderBlock($block, $this->varStack[$rendering]['variables'], $blocks);
+                $html = $this->template->renderBlock($types[$typeIndex], $this->varStack[$rendering]['variables'], $blocks);
 
                 if ($mainTemplate) {
                     $view->setRendered();
@@ -269,7 +269,10 @@ class FormExtension extends \Twig_Extension
             }
         } while (--$typeIndex >= 0);
 
-        throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $types)));
+        throw new FormException(sprintf(
+            'Unable to render the form as none of the following blocks exist: "%s".',
+            implode('", "', array_reverse($types))
+        ));
     }
 
     /**

+ 6 - 3
src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php

@@ -199,8 +199,8 @@ class FormHelper extends Helper
         }
 
         do {
-            $block = $types[$typeIndex].'_'.$section;
-            $template = $this->lookupTemplate($block);
+            $types[$typeIndex] .= '_'.$section;
+            $template = $this->lookupTemplate($types[$typeIndex]);
 
             if ($template) {
 
@@ -221,7 +221,10 @@ class FormHelper extends Helper
             }
         }  while (--$typeIndex >= 0);
 
-        throw new FormException(sprintf('Unable to render the form as none of the following blocks exist: "%s".', implode('", "', $types)));
+        throw new FormException(sprintf(
+            'Unable to render the form as none of the following blocks exist: "%s".',
+            implode('", "', array_reverse($types))
+        ));
     }
 
     /**