From 41cd370aa213409fbe21285ff681ceb7646987f1 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Mon, 15 Jan 2018 19:27:52 +0100 Subject: [PATCH] added service alias for auto-wiring using context helper to load body_class options --- Resources/config/services.yml | 4 +++- Twig/AvanzuAdminExtension.php | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index f9febc9e..3d9f9205 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -31,7 +31,7 @@ services: class: "%avanzu_admin_theme.extension.class%" tags: - { name: twig.extension } - arguments: ['%avanzu_admin_theme.options%', '%kernel.environment%', "@avanzu_admin_theme.admin_router"] + arguments: ['@avanzu_admin_theme.context_helper', '%kernel.environment%', "@avanzu_admin_theme.admin_router"] avanzu_admin_theme.context_helper: class: "%avanzu_admin_theme.context_helper.class%" @@ -39,5 +39,7 @@ services: - "%avanzu_admin_theme.options%" - "@avanzu_admin_theme.admin_router" + Avanzu\AdminThemeBundle\Helper\ContextHelper: + alias: avanzu_admin_theme.context_helper diff --git a/Twig/AvanzuAdminExtension.php b/Twig/AvanzuAdminExtension.php index ebf5be38..31ed8a30 100644 --- a/Twig/AvanzuAdminExtension.php +++ b/Twig/AvanzuAdminExtension.php @@ -7,11 +7,18 @@ namespace Avanzu\AdminThemeBundle\Twig; +use Avanzu\AdminThemeBundle\Helper\ContextHelper; use Avanzu\AdminThemeBundle\Routing\RouteAliasCollection; class AvanzuAdminExtension extends \Twig_Extension { - protected $options; + /** + * @var ContextHelper + */ + protected $context; + /** + * @var string + */ protected $env; /** * @var RouteAliasCollection @@ -20,14 +27,13 @@ class AvanzuAdminExtension extends \Twig_Extension /** * AvanzuAdminExtension constructor. - * - * @param $options - * @param $env + * @param ContextHelper $contextHelper + * @param $env * @param RouteAliasCollection $aliasRouter */ - public function __construct($options, $env, RouteAliasCollection $aliasRouter) + public function __construct(ContextHelper $contextHelper, $env, RouteAliasCollection $aliasRouter) { - $this->options = $options; + $this->context = $contextHelper; $this->env = $env; $this->aliasRouter = $aliasRouter; } @@ -43,7 +49,7 @@ public function getFilters() public function bodyClass($classes = '') { $classList = [$classes]; - $options = $this->options; + $options = $this->context->getOptions(); if(isset($options['skin'])) $classList[] = $options['skin']; if(isset($options['fixed_layout']) && true == $options['fixed_layout']) $classList[] = 'fixed';