public function ThemeSwitcherNegotiator::applies in Context 8.4
Same name and namespace in other branches
- 8 src/Theme/ThemeSwitcherNegotiator.php \Drupal\context\Theme\ThemeSwitcherNegotiator::applies()
Whether this theme negotiator should be used to set the theme.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match object.
Return value
bool TRUE if this negotiator should be used or FALSE to let other negotiators decide.
Overrides ThemeNegotiatorInterface::applies
File
- src/
Theme/ ThemeSwitcherNegotiator.php, line 50
Class
- ThemeSwitcherNegotiator
- Context Theme Switcher Negotiator.
Namespace
Drupal\context\ThemeCode
public function applies(RouteMatchInterface $route_match) {
// If there is no Theme reaction set or this method has already been
// executed, do not try to get active reactions, since this causes infinite
// loop.
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();
// Be sure the theme key really exists.
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;
}