[Twig][Form] Optimize form rendering
This commit is contained in:
parent
fed6dc9a1e
commit
eb10c66a55
@ -33,6 +33,8 @@ class FormExtension extends \Twig_Extension
|
||||
{
|
||||
$this->themes = new \SplObjectStorage();
|
||||
$this->varStack = new \SplObjectStorage();
|
||||
$this->templates = new \SplObjectStorage();
|
||||
|
||||
$this->resources = $resources;
|
||||
}
|
||||
|
||||
@ -53,6 +55,7 @@ class FormExtension extends \Twig_Extension
|
||||
public function setTheme(FormView $view, array $resources)
|
||||
{
|
||||
$this->themes->attach($view, $resources);
|
||||
$this->templates->detach($view);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,12 +186,20 @@ class FormExtension extends \Twig_Extension
|
||||
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the templates used by the view.
|
||||
*
|
||||
* templates are looked for in the following resources:
|
||||
* * resources from the themes (and its parents)
|
||||
* * default resources
|
||||
*
|
||||
* @param FormView $view The view
|
||||
*
|
||||
* @return array An array of Twig_TemplateInterface instances
|
||||
*/
|
||||
protected function getTemplates(FormView $view)
|
||||
{
|
||||
// templates are looked for in the following resources:
|
||||
// * resources from the themes (and its parents)
|
||||
// * default resources
|
||||
|
||||
if (!$this->templates->contains($view)) {
|
||||
// defaults
|
||||
$all = $this->resources;
|
||||
|
||||
@ -214,6 +225,11 @@ class FormExtension extends \Twig_Extension
|
||||
$templates = array_replace($templates, $blocks);
|
||||
}
|
||||
|
||||
$this->templates->attach($view, $templates);
|
||||
} else {
|
||||
$templates = $this->templates[$view];
|
||||
}
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ class FormHelper extends Helper
|
||||
$template = $this->templateDir.':'.$template;
|
||||
}
|
||||
*/
|
||||
$template = 'FrameworkBundle:Form:'.$template;
|
||||
$template = 'FrameworkBundle:Form:'.$template;
|
||||
if (!$this->engine->exists($template)) {
|
||||
$template = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user