ThemeSwitcherNegotiator.php in Context 8.4
File
src/Theme/ThemeSwitcherNegotiator.php
View source
<?php
namespace Drupal\context\Theme;
use Drupal\context\ContextManager;
use Drupal\context\Plugin\ContextReaction\Theme;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface {
private $contextManager;
protected $theme;
protected $evaluated;
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
$this->evaluated = FALSE;
}
public function applies(RouteMatchInterface $route_match) {
if ($this->evaluated) {
$this->evaluated = FALSE;
return FALSE;
}
$theme_reaction = FALSE;
foreach ($this->contextManager
->getContexts() as $context) {
foreach ($context
->getReactions() as $reaction) {
if ($reaction instanceof Theme) {
$theme_reaction = TRUE;
break;
}
}
}
if ($theme_reaction) {
$this->evaluated = TRUE;
foreach ($this->contextManager
->getActiveReactions('theme') as $theme_reaction) {
$configuration = $theme_reaction
->getConfiguration();
if (isset($configuration['theme'])) {
switch ($configuration['theme']) {
case '_admin':
$this->theme = \Drupal::config('system.theme')
->get('admin');
return TRUE;
case '_default':
$this->theme = \Drupal::config('system.theme')
->get('default');
return TRUE;
default:
$this->theme = $configuration['theme'];
return TRUE;
}
}
}
}
return FALSE;
}
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->theme;
}
}