[FrameworkBundle] Advanced search templates of bundles

It uses two different locations to search templates of bundle,
as described in the documentation.
This commit is contained in:
yethee 2015-09-20 23:05:20 +03:00 committed by Fabien Potencier
parent 25dccf1bb5
commit 3ba14604a7
4 changed files with 7 additions and 2 deletions

View File

@ -97,8 +97,12 @@ class TemplateFinder implements TemplateFinderInterface
*/
private function findTemplatesInBundle(BundleInterface $bundle)
{
$templates = $this->findTemplatesInFolder($bundle->getPath().'/Resources/views');
$name = $bundle->getName();
$templates = array_merge(
$this->findTemplatesInFolder($bundle->getPath().'/Resources/views'),
$this->findTemplatesInFolder($this->rootDir.'/'.$name.'/views')
);
$templates = array_unique($templates);
foreach ($templates as $i => $template) {
$templates[$i] = $template->set('bundle', $name);

View File

@ -46,10 +46,11 @@ class TemplateFinderTest extends TestCase
$finder->findAllTemplates()
);
$this->assertCount(6, $templates, '->findAllTemplates() find all templates in the bundles and global folders');
$this->assertCount(7, $templates, '->findAllTemplates() find all templates in the bundles and global folders');
$this->assertContains('BaseBundle::base.format.engine', $templates);
$this->assertContains('BaseBundle::this.is.a.template.format.engine', $templates);
$this->assertContains('BaseBundle:controller:base.format.engine', $templates);
$this->assertContains('BaseBundle:controller:custom.format.engine', $templates);
$this->assertContains('::this.is.a.template.format.engine', $templates);
$this->assertContains('::resource.format.engine', $templates);
}