diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index cd30dcaaae6d..8406a9c7a492 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -35,6 +35,8 @@ class FormHelper extends Helper protected $themes; + protected $templates; + /** * Constructor; * @@ -46,7 +48,8 @@ public function __construct(EngineInterface $engine, array $resources = array()) $this->engine = $engine; $this->varStack = array(); $this->context = array(); - $this->themes = new \SplObjectStorage(); + $this->templates = array(); + $this->themes = array(); $this->resources = 0 == count($resources) ? array('FrameworkBundle:Form') : $resources; @@ -72,7 +75,8 @@ public function isChoiceSelected(FormView $view, $choice) */ public function setTheme(FormView $view, $themes) { - $this->themes[$view] = (array) $themes; + $this->themes[$view->get('id')] = (array) $themes; + $this->templates = array(); } /** @@ -274,43 +278,47 @@ public function renderBlock($name, $variables = array()) return $this->engine->render($template, $variables); } + public function getName() + { + return 'form'; + } + /** * Returns the name of the template to use to render the block * - * @param FormView $view The form view - * @param string $blockName The name of the block + * @param FormView $view The form view + * @param string $block The name of the block * * @return string|Boolean The template logical name or false when no template is found */ protected function lookupTemplate(FormView $view, $block) { - $file = $block.'.html.php'; + $id = $view->get('id'); - $themes = $view->hasParent() ? array() : $this->resources; + if (!isset($this->templates[$id][$block])) { + $template = false; - if ($this->themes->contains($view)) { - $themes = array_merge($themes, $this->themes[$view]); - } + $themes = $view->hasParent() ? array() : $this->resources; - for ($i = count($themes) - 1; $i >= 0; --$i) { + if (isset($this->themes[$id])) { + $themes = array_merge($themes, $this->themes[$id]); + } - $template = $themes[$i].':'.$file; + for ($i = count($themes) - 1; $i >= 0; --$i) { + if ($this->engine->exists($templateName = $themes[$i].':'.$file)) { + $template = $templateName; + break; + } + } - if ($this->engine->exists($template)) { - return $template; + if (false === $template && $view->hasParent()) { + $template = $this->lookupTemplate($view->getParent(), $block); } - } - if ($view->hasParent()) { - return $this->lookupTemplate($view->getParent(), $block); + $this->templates[$id][$block] = $template; } - return false; - } - - public function getName() - { - return 'form'; + return $this->templates[$id][$block]; } }