From 3e0d844efcb1c5a70a2d2967b9a03f16c0c52e67 Mon Sep 17 00:00:00 2001 From: batopa Date: Tue, 19 May 2020 17:11:45 +0200 Subject: [PATCH 1/2] feat: setup twig environment via conf default for strict_variables set to false --- src/View/TwigView.php | 12 ++++++++++++ tests/TestCase/View/TwigViewTest.php | 1 + 2 files changed, 13 insertions(+) diff --git a/src/View/TwigView.php b/src/View/TwigView.php index 95dcb71..384b6ee 100644 --- a/src/View/TwigView.php +++ b/src/View/TwigView.php @@ -15,6 +15,7 @@ namespace BEdita\WebTools\View; use BEdita\WebTools\View\Twig\BeditaTwigExtension; +use Cake\Core\Configure; use Cake\TwigView\View\TwigView as BaseTwigView; /** @@ -22,6 +23,17 @@ */ class TwigView extends BaseTwigView { + /** + * {@inheritDoc} + */ + public function initialize(): void + { + $environment = Configure::read('Twig.environment', []) + ['strict_variables' => false]; + $this->setConfig('environment', $environment); + + parent::initialize(); + } + /** * {@inheritDoc} */ diff --git a/tests/TestCase/View/TwigViewTest.php b/tests/TestCase/View/TwigViewTest.php index d0f95f3..f261165 100644 --- a/tests/TestCase/View/TwigViewTest.php +++ b/tests/TestCase/View/TwigViewTest.php @@ -36,5 +36,6 @@ public function testInitialize(): void $extensions = $View->getTwig()->getExtensions(); static::assertNotEmpty($extensions); static::assertArrayHasKey('BEdita\WebTools\View\Twig\BeditaTwigExtension', $extensions); + static::assertFalse($View->getConfig('environment.strict_variables')); } } From 5c54e295a089b616bb3bfb9b0d4ca07fab2a45d4 Mon Sep 17 00:00:00 2001 From: batopa Date: Tue, 19 May 2020 17:17:38 +0200 Subject: [PATCH 2/2] chore: avoid array union errors --- src/View/TwigView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/TwigView.php b/src/View/TwigView.php index 384b6ee..5d7050a 100644 --- a/src/View/TwigView.php +++ b/src/View/TwigView.php @@ -28,7 +28,7 @@ class TwigView extends BaseTwigView */ public function initialize(): void { - $environment = Configure::read('Twig.environment', []) + ['strict_variables' => false]; + $environment = (array)Configure::read('Twig.environment', []) + ['strict_variables' => false]; $this->setConfig('environment', $environment); parent::initialize();