diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index b6338db06d84..7d04441234a6 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -226,12 +226,12 @@ protected function render(FormView $view, $section, array $variables = array()) $blocks = $this->getBlocks($view); $types = $view->get('types'); - array_unshift($types, '_'.$view->get('proto_id', $view->get('id'))); + $types[] = '_'.$view->get('proto_id', $view->get('id')); - foreach ($types as &$block) { - $block = $block.'_'.$section; + for ($i = count($types) - 1; $i >= 0; $i--) { + $types[$i] .= '_'.$section; - if (isset($blocks[$block])) { + if (isset($blocks[$types[$i]])) { $this->varStack[$view] = array_replace( $view->all(), @@ -239,7 +239,7 @@ protected function render(FormView $view, $section, array $variables = array()) $variables ); - $html = $this->template->renderBlock($block, $this->varStack[$view], $blocks); + $html = $this->template->renderBlock($types[$i], $this->varStack[$view], $blocks); if ($mainTemplate) { $view->setRendered(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index cb3111bd1723..135171f48d87 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -202,29 +202,25 @@ protected function renderSection(FormView $view, $section, array $variables = ar } $template = null; - $blocks = $view->get('types'); - array_unshift($blocks, '_'.$view->get('proto_id', $view->get('id'))); + $types = $view->get('types'); + $types[] = '_'.$view->get('proto_id', $view->get('id')); - foreach ($blocks as &$block) { - $block = $block.'_'.$section; - $template = $this->lookupTemplate($block); + for ($i = count($types) - 1; $i >= 0; $i--) { + $types[$i] .= '_'.$section; + $template = $this->lookupTemplate($types[$i]); if ($template) { - break; - } - } - - if (!$template) { - throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks))); - } + $html = $this->render($view, $template, $variables); - $html = $this->render($view, $template, $variables); + if ($mainTemplate) { + $view->setRendered(); + } - if ($mainTemplate) { - $view->setRendered(); + return $html; + } } - return $html; + throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $types))); } public function render(FormView $view, $template, array $variables = array()) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php index d0935c630481..c60d55c3c7be 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php @@ -75,11 +75,6 @@ public function buildView(FormView $view, FormInterface $form) $fullName = $name; } - $types = array(); - foreach (array_reverse((array) $form->getTypes()) as $type) { - $types[] = $type->getName(); - } - $view ->set('form', $view) ->set('id', $id) @@ -95,7 +90,7 @@ public function buildView(FormView $view, FormInterface $form) ->set('label', $form->getAttribute('label')) ->set('multipart', false) ->set('attr', array()) - ->set('types', $types) + ->set('types', array_map(function ($type) { return $type->getName(); }, $form->getTypes())) ; } diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index f86920ac15ef..1f28935f82e6 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -921,7 +921,7 @@ public function createView(FormView $parent = null) if (null !== $prototype = $view->get('prototype')) { $protoView = $prototype->getForm()->createView($view); $protoTypes = $protoView->get('types'); - array_unshift($protoTypes, 'prototype'); + $protoTypes[] = 'prototype'; $childViews[$prototype->getName()] = $protoView ->set('types', $protoTypes) ->set('proto_id', $view->get('id').'_prototype');