moved twig globals to dynamic compiler pass (#264)

This commit is contained in:
Kevin Papst
2018-08-10 00:11:48 +02:00
committed by GitHub
parent 3dcd38eca7
commit c6e99b35d5
10 changed files with 128 additions and 20 deletions

View File

@@ -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
],
]
);
*/
}
/**

View 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]);
}
}

View File

@@ -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()