[TwigBundle] added the security context and the user as global variables when they are defined
This commit is contained in:
parent
1c3a01b25c
commit
50809d2ae0
@ -4,6 +4,7 @@ namespace Symfony\Bundle\TwigBundle\Renderer;
|
|||||||
|
|
||||||
use Symfony\Component\Templating\Renderer\Renderer as BaseRenderer;
|
use Symfony\Component\Templating\Renderer\Renderer as BaseRenderer;
|
||||||
use Symfony\Component\Templating\Storage\Storage;
|
use Symfony\Component\Templating\Storage\Storage;
|
||||||
|
use Symfony\Component\Templating\Engine;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the Symfony package.
|
* This file is part of the Symfony package.
|
||||||
@ -27,6 +28,24 @@ class Renderer extends BaseRenderer
|
|||||||
$this->environment = $environment;
|
$this->environment = $environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setEngine(Engine $engine)
|
||||||
|
{
|
||||||
|
parent::setEngine($engine);
|
||||||
|
|
||||||
|
$container = $engine->getContainer();
|
||||||
|
if ($container->has('security.context')) {
|
||||||
|
$security = $container->get('security.context');
|
||||||
|
$this->environment->addGlobal('security', $security);
|
||||||
|
|
||||||
|
if ($user = $security->getUser()) {
|
||||||
|
$this->environment->addGlobal('user', $user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluates a template.
|
* Evaluates a template.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user