Skip to content

Commit

Permalink
Replace default twig.loader.filesystem in more flexible way
Browse files Browse the repository at this point in the history
  • Loading branch information
xanido committed Feb 11, 2015
1 parent c501b2d commit 6b56b90
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
22 changes: 21 additions & 1 deletion DependencyInjection/Compiler/ThemeCompilerPass.php
Expand Up @@ -23,11 +23,31 @@ public function process(ContainerBuilder $container)

$container->setAlias('templating.cache_warmer.template_paths', 'liip_theme.templating.cache_warmer.template_paths');

$container->setAlias('twig.loader', 'liip_theme.twig.loader.filesystem');
if (true === $container->hasDefinition('twig')) {
$twigLoader = $container->findDefinition('twig.loader');
if ('Twig_Loader_Chain' == $class = $container->getParameterBag()->resolveValue($twigLoader->getClass())) {
$methodCalls = $twigLoader->getMethodCalls();
foreach($methodCalls as $index => $methodCall) {
if ($methodCall[0] == 'addLoader' && (string) $methodCall[1][0] == 'twig.loader.filesystem') {
$methodCalls[$index] = array($methodCall[0], array(new Reference('liip_theme.twig.loader.filesystem')));
}
}
$twigLoader->setMethodCalls($methodCalls);
} else {
$id = 'twig.loader';
while($container->hasAlias($id)) {
$id = $container->getAlias($id);
}
if($id == 'twig.loader.filesystem') {
$container->setAlias('twig.loader', 'liip_theme.twig.loader.filesystem');
}
}
}

if (!$container->getParameter('liip_theme.cache_warming')) {
$container->getDefinition('liip_theme.templating.cache_warmer.template_paths')
->replaceArgument(2, null);
}
}

}
3 changes: 0 additions & 3 deletions Loader/FilesystemLoader.php
Expand Up @@ -36,7 +36,4 @@ protected function findTemplate($template)
return $file;
}




}
1 change: 0 additions & 1 deletion Resources/config/templating.xml
Expand Up @@ -30,7 +30,6 @@
<argument type="service" id="templating.locator" />
<argument type="service" id="templating.name_parser" />
<argument type="service" id="liip_theme.active_theme" />
<tag name="twig.loader"/>
</service>

<service id="liip_theme.file_locator" class="%liip_theme.file_locator.class%" public="false">
Expand Down

0 comments on commit 6b56b90

Please sign in to comment.