moved Twig form templates to the Twig bridge
This commit is contained in:
parent
1363068686
commit
89f544afb6
11
UPDATE.md
11
UPDATE.md
@ -9,6 +9,17 @@ timeline closely anyway.
|
||||
beta4 to beta5
|
||||
--------------
|
||||
|
||||
* Default Twig form templates have been moved to the Twig bridge. Here is how
|
||||
you can reference them now from a template or in a configuration setting:
|
||||
|
||||
Before:
|
||||
|
||||
`TwigBundle:Form:div_layout.html.twig`
|
||||
|
||||
After:
|
||||
|
||||
`div_layout.html.twig`
|
||||
|
||||
* All settings regarding the cache warmers have been removed.
|
||||
|
||||
* `Response::isRedirected()` has been merged with `Response::isRedirect()`
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% use "TwigBundle:Form:div_layout.html.twig" %}
|
||||
{% use "div_layout.html.twig" %}
|
||||
|
||||
{% block field_row %}
|
||||
{% spaceless %}
|
@ -62,11 +62,11 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->arrayNode('resources')
|
||||
->addDefaultsIfNotSet()
|
||||
->defaultValue(array('TwigBundle:Form:div_layout.html.twig'))
|
||||
->defaultValue(array('div_layout.html.twig'))
|
||||
->validate()
|
||||
->always()
|
||||
->then(function($v){
|
||||
return array_merge(array('TwigBundle:Form:div_layout.html.twig'), $v);
|
||||
return array_merge(array('div_layout.html.twig'), $v);
|
||||
})
|
||||
->end()
|
||||
->prototype('scalar')->end()
|
||||
|
@ -42,6 +42,7 @@ class TwigExtension extends Extension
|
||||
$config = $processor->processConfiguration($configuration, $configs);
|
||||
|
||||
$container->setParameter('twig.form.resources', $config['form']['resources']);
|
||||
$container->getDefinition('twig.loader')->addMethodCall('addPath', array(__DIR__.'/../../../Bridge/Twig/Resources/views/Form'));
|
||||
|
||||
if (!empty($config['globals'])) {
|
||||
$def = $container->getDefinition('twig');
|
||||
|
@ -21,7 +21,7 @@ use Symfony\Component\Templating\TemplateReferenceInterface;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class FilesystemLoader implements \Twig_LoaderInterface
|
||||
class FilesystemLoader extends \Twig_Loader_Filesystem
|
||||
{
|
||||
protected $locator;
|
||||
protected $parser;
|
||||
@ -40,43 +40,6 @@ class FilesystemLoader implements \Twig_LoaderInterface
|
||||
$this->cache = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source code of a template, given its name.
|
||||
*
|
||||
* @param mixed $name The template name or a TemplateReferenceInterface instance
|
||||
*
|
||||
* @return string The template source code
|
||||
*/
|
||||
public function getSource($name)
|
||||
{
|
||||
return file_get_contents($this->findTemplate($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cache key to use for the cache for a given template name.
|
||||
*
|
||||
* @param mixed $name The template name or a TemplateReferenceInterface instance
|
||||
*
|
||||
* @return string The cache key
|
||||
*/
|
||||
public function getCacheKey($name)
|
||||
{
|
||||
return $this->findTemplate($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the template is still fresh.
|
||||
*
|
||||
* @param mixed $name The template name or a TemplateReferenceInterface instance
|
||||
* @param timestamp $time The last modification time of the cached template
|
||||
*
|
||||
* @throws \Twig_Error_Loader if the template does not exist
|
||||
*/
|
||||
public function isFresh($name, $time)
|
||||
{
|
||||
return filemtime($this->findTemplate($name)) < $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the template file
|
||||
*
|
||||
@ -86,7 +49,11 @@ class FilesystemLoader implements \Twig_LoaderInterface
|
||||
*/
|
||||
protected function findTemplate($name)
|
||||
{
|
||||
$tpl = $this->parser->parse($name);
|
||||
try {
|
||||
$tpl = $this->parser->parse($name);
|
||||
} catch (\Exception $e) {
|
||||
return parent::findTemplate($name);
|
||||
}
|
||||
|
||||
if (isset($this->cache[$key = $tpl->getLogicalName()])) {
|
||||
return $this->cache[$key];
|
||||
|
@ -31,7 +31,7 @@ class TwigExtensionTest extends TestCase
|
||||
$this->compileContainer($container);
|
||||
|
||||
$this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file');
|
||||
$this->assertContains('TwigBundle:Form:div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources');
|
||||
$this->assertContains('div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources');
|
||||
|
||||
// Twig options
|
||||
$options = $container->getParameter('twig.options');
|
||||
@ -60,7 +60,7 @@ class TwigExtensionTest extends TestCase
|
||||
|
||||
// Form resources
|
||||
$resources = $container->getParameter('twig.form.resources');
|
||||
$this->assertContains('TwigBundle:Form:div_layout.html.twig', $resources, '->load() includes default template for form resources');
|
||||
$this->assertContains('div_layout.html.twig', $resources, '->load() includes default template for form resources');
|
||||
$this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources');
|
||||
|
||||
// Globals
|
||||
|
@ -32,7 +32,7 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
|
||||
parent::setUp();
|
||||
|
||||
$loader = new StubFilesystemLoader(array(
|
||||
__DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form',
|
||||
__DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
|
||||
__DIR__,
|
||||
));
|
||||
|
||||
|
@ -32,7 +32,7 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
|
||||
parent::setUp();
|
||||
|
||||
$loader = new StubFilesystemLoader(array(
|
||||
__DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form',
|
||||
__DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
|
||||
__DIR__,
|
||||
));
|
||||
|
||||
|
Reference in New Issue
Block a user