class ThemeSwitcherNegotiator in Context 8
Same name and namespace in other branches
- 8.4 src/Theme/ThemeSwitcherNegotiator.php \Drupal\context\Theme\ThemeSwitcherNegotiator
Context Theme Switcher Negotiator.
Hierarchy
- class \Drupal\context\Theme\ThemeSwitcherNegotiator implements ThemeNegotiatorInterface
Expanded class hierarchy of ThemeSwitcherNegotiator
1 string reference to 'ThemeSwitcherNegotiator'
1 service uses ThemeSwitcherNegotiator
File
- src/
Theme/ ThemeSwitcherNegotiator.php, line 13
Namespace
Drupal\context\ThemeView source
class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface {
/**
* ContextManager.
*
* @var \Drupal\context\ContextManager
*/
private $contextManager;
/**
* Theme machine name.
*
* @var string
*/
protected $theme;
/**
* Service constructor.
*
* @param \Drupal\context\ContextManager $contextManager
* ContextManager.
*/
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
// If there is no Theme reaction set, do not try to get active reactions,
// since this causes infinite loop.
$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) {
foreach ($this->contextManager
->getActiveReactions('theme') as $theme_reaction) {
$configuration = $theme_reaction
->getConfiguration();
$this->theme = $configuration['theme'];
return TRUE;
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->theme;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemeSwitcherNegotiator:: |
private | property | ContextManager. | |
ThemeSwitcherNegotiator:: |
protected | property | Theme machine name. | |
ThemeSwitcherNegotiator:: |
public | function |
Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface:: |
|
ThemeSwitcherNegotiator:: |
public | function |
Determine the active theme for the request. Overrides ThemeNegotiatorInterface:: |
|
ThemeSwitcherNegotiator:: |
public | function | Service constructor. |