added global variables access in a form theme (closes #3058)
This commit is contained in:
parent
7f0274462f
commit
878e86db8a
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
2.1.0
|
2.1.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* added global variables access in a form theme
|
||||||
* added TwigEngine
|
* added TwigEngine
|
||||||
* added TwigExtractor
|
* added TwigExtractor
|
||||||
* added a csrf_token function
|
* added a csrf_token function
|
||||||
|
@ -259,9 +259,11 @@ class FormExtension extends \Twig_Extension
|
|||||||
if (isset($blocks[$types[$typeIndex]])) {
|
if (isset($blocks[$types[$typeIndex]])) {
|
||||||
$this->varStack[$rendering]['typeIndex'] = $typeIndex;
|
$this->varStack[$rendering]['typeIndex'] = $typeIndex;
|
||||||
|
|
||||||
|
$context = $this->environment->mergeGlobals($this->varStack[$rendering]['variables']);
|
||||||
|
|
||||||
// we do not call renderBlock here to avoid too many nested level calls (XDebug limits the level to 100 by default)
|
// we do not call renderBlock here to avoid too many nested level calls (XDebug limits the level to 100 by default)
|
||||||
ob_start();
|
ob_start();
|
||||||
$this->template->displayBlock($types[$typeIndex], $this->varStack[$rendering]['variables'], $blocks);
|
$this->template->displayBlock($types[$typeIndex], $context, $blocks);
|
||||||
$html = ob_get_clean();
|
$html = ob_get_clean();
|
||||||
|
|
||||||
if ($mainTemplate) {
|
if ($mainTemplate) {
|
||||||
|
@ -52,9 +52,10 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
|||||||
'custom_widgets.html.twig',
|
'custom_widgets.html.twig',
|
||||||
));
|
));
|
||||||
|
|
||||||
$environment = new \Twig_Environment($loader);
|
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
||||||
$environment->addExtension($this->extension);
|
$environment->addExtension($this->extension);
|
||||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
|
$environment->addGlobal('global', '');
|
||||||
|
|
||||||
$this->extension->initRuntime($environment);
|
$this->extension->initRuntime($environment);
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,10 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
|||||||
'custom_widgets.html.twig',
|
'custom_widgets.html.twig',
|
||||||
));
|
));
|
||||||
|
|
||||||
$environment = new \Twig_Environment($loader);
|
$environment = new \Twig_Environment($loader, array('strict_variables' => true));
|
||||||
$environment->addExtension($this->extension);
|
$environment->addExtension($this->extension);
|
||||||
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
$environment->addExtension(new TranslationExtension(new StubTranslator()));
|
||||||
|
$environment->addGlobal('global', '');
|
||||||
|
|
||||||
$this->extension->initRuntime($environment);
|
$this->extension->initRuntime($environment);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{% block form_label %}
|
{% block form_label %}
|
||||||
<label>child</label>
|
<label>{{ global }}child</label>
|
||||||
{% endblock form_label %}
|
{% endblock form_label %}
|
||||||
|
@ -33,6 +33,7 @@ class FormHelperDivLayoutTest extends AbstractDivLayoutTest
|
|||||||
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);
|
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);
|
||||||
$loader = new FilesystemLoader(array());
|
$loader = new FilesystemLoader(array());
|
||||||
$engine = new PhpEngine($templateNameParser, $loader);
|
$engine = new PhpEngine($templateNameParser, $loader);
|
||||||
|
$engine->addGlobal('global', '');
|
||||||
|
|
||||||
$this->helper = new FormHelper($engine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'), array('FrameworkBundle:Form'));
|
$this->helper = new FormHelper($engine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'), array('FrameworkBundle:Form'));
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ class FormHelperTableLayoutTest extends AbstractTableLayoutTest
|
|||||||
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);
|
$templateNameParser = new StubTemplateNameParser($root, $rootTheme);
|
||||||
$loader = new FilesystemLoader(array());
|
$loader = new FilesystemLoader(array());
|
||||||
$engine = new PhpEngine($templateNameParser, $loader);
|
$engine = new PhpEngine($templateNameParser, $loader);
|
||||||
|
$engine->addGlobal('global', '');
|
||||||
|
|
||||||
$this->helper = new FormHelper($engine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'), array(
|
$this->helper = new FormHelper($engine, $this->getMock('Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface'), array(
|
||||||
'FrameworkBundle:Form',
|
'FrameworkBundle:Form',
|
||||||
|
@ -1 +1 @@
|
|||||||
<label>child</label>
|
<label><?php echo $global ?>child</label>
|
||||||
|
Reference in New Issue
Block a user