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 e751079
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
25 changes: 24 additions & 1 deletion DependencyInjection/Compiler/ThemeCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,34 @@ 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');
$aliasedTo = $this->resolveAlias('twig.loader', $container);
if ($aliasedTo == 'twig.loader.chain') {
$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);
} elseif ($aliasedTo == 'twig.loader.filesystem') {
$container->setAlias('twig.loader.filesystem', 'liip_theme.twig.loader.filesystem');
}
}

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

public function resolveContainerAlias($id, ContainerBuilder $container) {
while($container->hasAlias($id)) {
$id = $container->getAlias($id);
}

return $id;
}

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




}
1 change: 0 additions & 1 deletion Resources/config/templating.xml
Original file line number Diff line number Diff line change
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 e751079

Please sign in to comment.