diff --git a/context.services.yml b/context.services.yml index 5583251..67aa049 100644 --- a/context.services.yml +++ b/context.services.yml @@ -12,5 +12,6 @@ services: - { name: event_subscriber } theme.negotiator.context_themeswitcher: class: Drupal\context\Theme\ThemeSwitcherNegotiator + arguments: ['@context.manager'] tags: - { name: theme_negotiator, priority: 1000 } diff --git a/src/Theme/ThemeSwitcherNegotiator.php b/src/Theme/ThemeSwitcherNegotiator.php index 6ce7340..0696f41 100644 --- a/src/Theme/ThemeSwitcherNegotiator.php +++ b/src/Theme/ThemeSwitcherNegotiator.php @@ -1,32 +1,49 @@ contextManager = $contextManager; + } + /** * {@inheritdoc} */ public function applies(RouteMatchInterface $route_match) { - $context_manager = \Drupal::service('context.manager'); - // If there is no Theme reaction set, do not try to get active reactions, // since this causes infinite loop. $theme_reaction = FALSE; - foreach ($context_manager->getContexts() as $context) { + foreach ($this->contextManager->getContexts() as $context) { foreach ($context->getReactions() as $reaction) { if ($reaction instanceof Theme) { $theme_reaction = TRUE; @@ -36,7 +53,7 @@ class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface { } if ($theme_reaction) { - foreach($context_manager->getActiveReactions('theme') as $theme_reaction) { + foreach ($this->contextManager->getActiveReactions('theme') as $theme_reaction) { $configuration = $theme_reaction->getConfiguration(); $this->theme = $configuration['theme']; return TRUE; @@ -52,4 +69,5 @@ class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface { public function determineActiveTheme(RouteMatchInterface $route_match) { return $this->theme; } + }