[Form] Fixed rendering using the PHP Templating engine
This commit is contained in:
parent
fae319e77a
commit
ed69d7fa35
@ -37,26 +37,28 @@ class PhpEngineTheme implements FormThemeInterface
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $template;
|
||||
private $templateDir;
|
||||
|
||||
/**
|
||||
* @param PhpEngine $engine
|
||||
*/
|
||||
public function __construct(PhpEngine $engine, $template = null)
|
||||
public function __construct(PhpEngine $engine, $templateDir = null)
|
||||
{
|
||||
$this->engine = $engine;
|
||||
$this->template = $template;
|
||||
$this->templateDir = $templateDir;
|
||||
}
|
||||
|
||||
public function render($field, $section, array $parameters)
|
||||
public function render(array $blocks, $section, array $parameters)
|
||||
{
|
||||
if ($template = $this->lookupTemplate($field."_".$section)) {
|
||||
return $this->engine->render($template, $parameters);
|
||||
} else if ($template = $this->lookupTemplate($section)) {
|
||||
return $this->engine->render($template, $parameters);
|
||||
} else {
|
||||
throw new FormException(sprintf('The form theme is missing the "%s" template file.', $section));
|
||||
foreach ($blocks as &$block) {
|
||||
$block = $block.'_'.$section;
|
||||
|
||||
if ($template = $this->lookupTemplate($block)) {
|
||||
return $this->engine->render($template, $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
throw new FormException(sprintf('The form theme is missing the "%s" template files', implode('", "', $blocks)));
|
||||
}
|
||||
|
||||
protected function lookupTemplate($templateName)
|
||||
@ -65,7 +67,12 @@ class PhpEngineTheme implements FormThemeInterface
|
||||
return self::$cache[$templateName];
|
||||
}
|
||||
|
||||
$template = (($this->template) ? ($this->template.":") : "") . $templateName.'.html.php';
|
||||
$template = $templateName.'.html.php';
|
||||
|
||||
if ($this->templateDir) {
|
||||
$template = $this->templateDir . ':' . $template;
|
||||
}
|
||||
|
||||
if (!$this->engine->exists($template)) {
|
||||
$template = false;
|
||||
}
|
||||
|
@ -26,16 +26,22 @@ class PhpEngineThemeFactory implements FormThemeFactoryInterface
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
public function __construct(PhpEngine $engine)
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultTemplateDir;
|
||||
|
||||
public function __construct(PhpEngine $engine, $defaultTemplateDir = null)
|
||||
{
|
||||
$this->engine = $engine;
|
||||
$this->defaultTemplateDir = $defaultTemplateDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Symfony\Component\Form\Renderer\Theme\FormThemeFactoryInterface::create()
|
||||
*/
|
||||
public function create($template = null)
|
||||
public function create($templateDir = null)
|
||||
{
|
||||
return new PhpEngineTheme($this->engine, $template);
|
||||
return new PhpEngineTheme($this->engine, $templateDir ?: $this->defaultTemplateDir);
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@
|
||||
<parameter key="form.theme.factory.twig.class">Symfony\Component\Form\Renderer\Theme\TwigThemeFactory</parameter>
|
||||
<parameter key="form.theme.factory.php.class">Symfony\Component\Form\Renderer\Theme\PhpThemeFactory</parameter>
|
||||
<parameter key="form.theme.factory.phpengine.class">Symfony\Bundle\FrameworkBundle\Form\PhpEngineThemeFactory</parameter>
|
||||
<parameter key="form.theme.template">TwigBundle::div_layout.html.twig</parameter>
|
||||
<parameter key="form.theme.template.twig">TwigBundle::div_layout.html.twig</parameter>
|
||||
<parameter key="form.theme.template.phpengine">FrameworkBundle:Form</parameter>
|
||||
<parameter key="form.factory.class">Symfony\Component\Form\FormFactory</parameter>
|
||||
<parameter key="form.csrf_protection.enabled">true</parameter>
|
||||
<parameter key="form.csrf_protection.field_name">_token</parameter>
|
||||
@ -82,7 +83,7 @@
|
||||
<!-- Themes -->
|
||||
<service id="form.theme.factory.twig" class="%form.theme.factory.twig.class%">
|
||||
<argument type="service" id="twig" />
|
||||
<argument>%form.theme.template%</argument>
|
||||
<argument>%form.theme.template.twig%</argument>
|
||||
</service>
|
||||
|
||||
<service id="form.theme.factory.default" class="%form.theme.factory.php.class%">
|
||||
@ -91,6 +92,7 @@
|
||||
|
||||
<service id="form.theme.factory.php" class="%form.theme.factory.phpengine.class%">
|
||||
<argument type="service" id="templating.engine.php" />
|
||||
<argument>%form.theme.template.phpengine%</argument>
|
||||
</service>
|
||||
|
||||
<!-- TemporaryStorage - where should we put this? -->
|
||||
@ -129,8 +131,6 @@
|
||||
<service id="form.type.field" class="Symfony\Component\Form\Type\FieldType">
|
||||
<tag name="form.type" alias="field" />
|
||||
<argument type="service" id="validator" />
|
||||
<argument type="service" id="form.theme.factory" />
|
||||
<argument>%form.theme.template%</argument>
|
||||
</service>
|
||||
<service id="form.type.form" class="Symfony\Component\Form\Type\FormType">
|
||||
<tag name="form.type" alias="form" />
|
||||
|
@ -0,0 +1 @@
|
||||
<?php if ($renderer->getVar('multipart')): ?>enctype="multipart/form-data"<?php endif ?>
|
@ -106,9 +106,9 @@ class FilesystemLoader extends Loader
|
||||
*/
|
||||
static protected function isAbsolutePath($file)
|
||||
{
|
||||
if ($file[0] == '/' || $file[0] == '\\'
|
||||
|| (strlen($file) > 3 && ctype_alpha($file[0])
|
||||
&& $file[1] == ':'
|
||||
if ($file[0] == '/' || $file[0] == '\\'
|
||||
|| (strlen($file) > 3 && ctype_alpha($file[0])
|
||||
&& $file[1] == ':'
|
||||
&& ($file[2] == '\\' || $file[2] == '/')
|
||||
)
|
||||
) {
|
||||
|
Reference in New Issue
Block a user