Commit 0701edb1 authored by aronne's avatar aronne Committed by paulocs

Issue #3024989 by aronne, silverham, bzoks, paulocs: "Maximum function nesting...

Issue #3024989 by aronne, silverham, bzoks, paulocs: "Maximum function nesting level" error when creating a context with theme switcher reaction
parent c5ad8275
......@@ -26,6 +26,13 @@ class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface {
*/
protected $theme;
/**
* A boolean indicating if the applies method has already been evaluated.
*
* @var bool
*/
protected $evaluated;
/**
* Service constructor.
*
......@@ -34,14 +41,20 @@ class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface {
*/
public function __construct(ContextManager $contextManager) {
$this->contextManager = $contextManager;
$this->evaluated = FALSE;
}
/**
* {@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.
// 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) {
......@@ -53,10 +66,14 @@ class ThemeSwitcherNegotiator implements ThemeNegotiatorInterface {
}
if ($theme_reaction) {
$this->evaluated = TRUE;
foreach ($this->contextManager->getActiveReactions('theme') as $theme_reaction) {
$configuration = $theme_reaction->getConfiguration();
$this->theme = $configuration['theme'];
return TRUE;
// Be sure the theme key really exists.
if (isset($configuration['theme'])) {
$this->theme = $configuration['theme'];
return TRUE;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment