moved twig globals to dynamic compiler pass (#264)
This commit is contained in:
@@ -36,6 +36,7 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
|
||||
$container->setParameter('kimai.languages', $config['languages']);
|
||||
$container->setParameter('kimai.calendar', $config['calendar']);
|
||||
$container->setParameter('kimai.theme', $config['theme']);
|
||||
|
||||
$this->createUserParameter($config, $container);
|
||||
$this->createTimesheetParameter($config, $container);
|
||||
@@ -98,6 +99,7 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
*/
|
||||
public function prepend(ContainerBuilder $container)
|
||||
{
|
||||
/*
|
||||
$configuration = new Configuration();
|
||||
$configs = $container->getExtensionConfig($this->getAlias());
|
||||
try {
|
||||
@@ -115,6 +117,7 @@ class AppExtension extends Extension implements PrependExtensionInterface
|
||||
],
|
||||
]
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
33
src/DependencyInjection/Compiler/TwigContextCompilerPass.php
Normal file
33
src/DependencyInjection/Compiler/TwigContextCompilerPass.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Dynamically adds twig globals.
|
||||
*/
|
||||
class TwigContextCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$twig = $container->getDefinition('twig');
|
||||
$theme = $container->getParameter('kimai.theme');
|
||||
$durationOnly = $container->getParameter('kimai.timesheet.duration_only');
|
||||
|
||||
$twig->addMethodCall('addGlobal', ['kimai_context', $theme]);
|
||||
$twig->addMethodCall('addGlobal', ['duration_only', $durationOnly]);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,17 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('theme')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->integerNode('active_warning')
|
||||
->defaultValue(3)
|
||||
->end()
|
||||
->scalarNode('box_color')
|
||||
->defaultValue('green')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('user')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App;
|
||||
|
||||
use App\DependencyInjection\AppExtension;
|
||||
use App\DependencyInjection\Compiler\DoctrineCompilerPass;
|
||||
use App\DependencyInjection\Compiler\TwigContextCompilerPass;
|
||||
use App\Timesheet\CalculatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
@@ -66,6 +67,7 @@ class Kernel extends BaseKernel
|
||||
$loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
|
||||
|
||||
$container->addCompilerPass(new DoctrineCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000);
|
||||
$container->addCompilerPass(new TwigContextCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1000);
|
||||
}
|
||||
|
||||
protected function configureRoutes(RouteCollectionBuilder $routes)
|
||||
|
||||
Reference in New Issue
Block a user