From 564d8f7a6f33e5929bb0a4b2db71bc02eb85236e Mon Sep 17 00:00:00 2001 From: Damien Harper Date: Mon, 27 Sep 2021 00:15:59 +0200 Subject: [PATCH] Fix deprecation notice regarding twig usage from controller. Should help for Symfony 6 compat. (#273) --- src/Controller/ViewerController.php | 12 ++++++++++++ src/Resources/config/services.yaml | 1 + tests/DHAuditorBundleTest.php | 2 ++ tests/Twig/Extension/TwigExtensionTest.php | 2 ++ 4 files changed, 17 insertions(+) diff --git a/src/Controller/ViewerController.php b/src/Controller/ViewerController.php index 067acf12..880b149e 100644 --- a/src/Controller/ViewerController.php +++ b/src/Controller/ViewerController.php @@ -15,6 +15,13 @@ class ViewerController extends AbstractController { + private $environment; + + public function __construct(\Twig\Environment $environment) + { + $this->environment = $environment; + } + /** * @Route("/audit", name="dh_auditor_list_audits", methods={"GET"}) */ @@ -90,4 +97,9 @@ public function showEntityHistoryAction(Request $request, Reader $reader, string 'paginator' => $pager, ]); } + + protected function renderView(string $view, array $parameters = []): string + { + return $this->environment->render($view, $parameters); + } } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 33444b82..308666dc 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -60,6 +60,7 @@ services: # Bundle related services DH\AuditorBundle\Controller\ViewerController: + arguments: ['@twig'] calls: - { method: setContainer, arguments: ['@service_container'] } tags: ['controller.service_arguments'] diff --git a/tests/DHAuditorBundleTest.php b/tests/DHAuditorBundleTest.php index aec3331b..31a0a868 100644 --- a/tests/DHAuditorBundleTest.php +++ b/tests/DHAuditorBundleTest.php @@ -15,6 +15,7 @@ use Nyholm\BundleTest\BaseBundleTestCase; use Nyholm\BundleTest\CompilerPass\PublicServicePass; use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\HttpKernel\Kernel; /** @@ -44,6 +45,7 @@ public function testInitBundle(): void $kernel->addBundle(DoctrineBundle::class); $kernel->addBundle(SecurityBundle::class); + $kernel->addBundle(TwigBundle::class); $this->bootKernel(); diff --git a/tests/Twig/Extension/TwigExtensionTest.php b/tests/Twig/Extension/TwigExtensionTest.php index 2ce3f0b1..d5c62b90 100644 --- a/tests/Twig/Extension/TwigExtensionTest.php +++ b/tests/Twig/Extension/TwigExtensionTest.php @@ -8,6 +8,7 @@ use Nyholm\BundleTest\BaseBundleTestCase; use Nyholm\BundleTest\CompilerPass\PublicServicePass; use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\HttpKernel\Kernel; /** @@ -36,6 +37,7 @@ protected function setUp(): void $kernel->addBundle(DoctrineBundle::class); $kernel->addBundle(SecurityBundle::class); + $kernel->addBundle(TwigBundle::class); $this->bootKernel();