diff --git a/UPDATE.md b/UPDATE.md index 6f0f946668..5597ec9c80 100644 --- a/UPDATE.md +++ b/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()` diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/div_layout.html.twig similarity index 100% rename from src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig rename to src/Symfony/Bridge/Twig/Resources/views/Form/div_layout.html.twig diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Form/table_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/table_layout.html.twig similarity index 94% rename from src/Symfony/Bundle/TwigBundle/Resources/views/Form/table_layout.html.twig rename to src/Symfony/Bridge/Twig/Resources/views/Form/table_layout.html.twig index c495caa43a..d775abe893 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Form/table_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/table_layout.html.twig @@ -1,4 +1,4 @@ -{% use "TwigBundle:Form:div_layout.html.twig" %} +{% use "div_layout.html.twig" %} {% block field_row %} {% spaceless %} diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 0ccaf8b815..10da1a88f0 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -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() diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 388d214b35..432ee4f9fe 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -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'); diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index cae3e23b83..827cdcb83f 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -21,7 +21,7 @@ use Symfony\Component\Templating\TemplateReferenceInterface; * * @author Fabien Potencier */ -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]; diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 16dc0a3f5b..999afb0c2f 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -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 diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionDivLayoutTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionDivLayoutTest.php index ba9747e148..c2774e2f87 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionDivLayoutTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionDivLayoutTest.php @@ -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__, )); diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionTableLayoutTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionTableLayoutTest.php index 350b52c262..1373a7ebec 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionTableLayoutTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionTableLayoutTest.php @@ -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__, ));