Skip to content

Commit

Permalink
moved Twig form templates to the Twig bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 7, 2011
1 parent 1363068 commit 89f544a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 46 deletions.
11 changes: 11 additions & 0 deletions UPDATE.md
Expand Up @@ -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()`
Expand Down
@@ -1,4 +1,4 @@
{% use "TwigBundle:Form:div_layout.html.twig" %}
{% use "div_layout.html.twig" %}

{% block field_row %}
{% spaceless %}
Expand Down
Expand Up @@ -62,11 +62,11 @@ private function addFormSection(ArrayNodeDefinition $rootNode)
->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()
Expand Down
Expand Up @@ -42,6 +42,7 @@ public function load(array $configs, ContainerBuilder $container)
$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');
Expand Down
45 changes: 6 additions & 39 deletions src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
Expand Up @@ -21,7 +21,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class FilesystemLoader implements \Twig_LoaderInterface
class FilesystemLoader extends \Twig_Loader_Filesystem
{
protected $locator;
protected $parser;
Expand All @@ -40,43 +40,6 @@ public function __construct(FileLocatorInterface $locator, TemplateNameParserInt
$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
*
Expand All @@ -86,7 +49,11 @@ public function isFresh($name, $time)
*/
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];
Expand Down
Expand Up @@ -31,7 +31,7 @@ public function testLoadEmptyConfiguration()
$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');
Expand Down Expand Up @@ -60,7 +60,7 @@ public function testLoadFullConfiguration($format)

// 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
Expand Down
Expand Up @@ -32,7 +32,7 @@ protected function setUp()
parent::setUp();

$loader = new StubFilesystemLoader(array(
__DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form',
__DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
__DIR__,
));

Expand Down
Expand Up @@ -32,7 +32,7 @@ protected function setUp()
parent::setUp();

$loader = new StubFilesystemLoader(array(
__DIR__.'/../../../../../../src/Symfony/Bundle/TwigBundle/Resources/views/Form',
__DIR__.'/../../../../../../src/Symfony/Bridge/Twig/Resources/views/Form',
__DIR__,
));

Expand Down

0 comments on commit 89f544a

Please sign in to comment.