Loading src/ContextCollection.php +15 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ class ContextCollection implements ContextCollectionInterface { use DependencySerializationTrait { __sleep as goodNightServices; __wakeup as goodMorningServices; } /** Loading Loading @@ -435,6 +436,19 @@ class ContextCollection implements ContextCollectionInterface { }); } /** * Implements the magic wakeup method. */ public function __wakeup() { if (!$this->contextStackCacheContextIsAvailable()) { // When the "context_stack" cache context is missing on the next process, // we cannot apply proper caching on this collection. $this->cacheContexts = []; $this->cacheMaxAge = 0; } $this->goodMorningServices(); } /** * Check whether the service for "context_stack" cache contexts is available. * Loading @@ -442,7 +456,7 @@ class ContextCollection implements ContextCollectionInterface { * Returns TRUE if available, FALSE otherwise. */ protected function contextStackCacheContextIsAvailable(): bool { return in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); return \Drupal::hasContainer() && in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); } } src/ContextStack.php +3 −2 Original line number Diff line number Diff line Loading @@ -175,7 +175,8 @@ class ContextStack extends ContextCollection implements ContextStackInterface { */ public function getCacheContexts() { $cache_contexts = parent::getCacheContexts(); if ($this->hasPurpose() && $this->contextStackCacheContextIsAvailable()) { $cache_context_is_avalable = $this->contextStackCacheContextIsAvailable(); if ($this->hasPurpose() && $cache_context_is_avalable) { $cache_context_parameterized = 'context_stack:' . $this->getPurpose() . ':' . $this->generateChecksum(); if (!in_array($cache_context_parameterized, $cache_contexts, TRUE)) { $cache_contexts[] = $cache_context_parameterized; Loading @@ -191,7 +192,7 @@ class ContextStack extends ContextCollection implements ContextStackInterface { break; } } if (!$has_cache_context) { if (!$has_cache_context && $cache_context_is_avalable) { $cache_contexts[] = 'context_stack'; } Loading src/ContextStackTrait.php +1 −1 Original line number Diff line number Diff line Loading @@ -213,7 +213,7 @@ trait ContextStackTrait { * Returns TRUE if available, FALSE otherwise. */ protected function contextStackCacheContextIsAvailable(): bool { return in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); return \Drupal::hasContainer() && in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); } } Loading
src/ContextCollection.php +15 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ class ContextCollection implements ContextCollectionInterface { use DependencySerializationTrait { __sleep as goodNightServices; __wakeup as goodMorningServices; } /** Loading Loading @@ -435,6 +436,19 @@ class ContextCollection implements ContextCollectionInterface { }); } /** * Implements the magic wakeup method. */ public function __wakeup() { if (!$this->contextStackCacheContextIsAvailable()) { // When the "context_stack" cache context is missing on the next process, // we cannot apply proper caching on this collection. $this->cacheContexts = []; $this->cacheMaxAge = 0; } $this->goodMorningServices(); } /** * Check whether the service for "context_stack" cache contexts is available. * Loading @@ -442,7 +456,7 @@ class ContextCollection implements ContextCollectionInterface { * Returns TRUE if available, FALSE otherwise. */ protected function contextStackCacheContextIsAvailable(): bool { return in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); return \Drupal::hasContainer() && in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); } }
src/ContextStack.php +3 −2 Original line number Diff line number Diff line Loading @@ -175,7 +175,8 @@ class ContextStack extends ContextCollection implements ContextStackInterface { */ public function getCacheContexts() { $cache_contexts = parent::getCacheContexts(); if ($this->hasPurpose() && $this->contextStackCacheContextIsAvailable()) { $cache_context_is_avalable = $this->contextStackCacheContextIsAvailable(); if ($this->hasPurpose() && $cache_context_is_avalable) { $cache_context_parameterized = 'context_stack:' . $this->getPurpose() . ':' . $this->generateChecksum(); if (!in_array($cache_context_parameterized, $cache_contexts, TRUE)) { $cache_contexts[] = $cache_context_parameterized; Loading @@ -191,7 +192,7 @@ class ContextStack extends ContextCollection implements ContextStackInterface { break; } } if (!$has_cache_context) { if (!$has_cache_context && $cache_context_is_avalable) { $cache_contexts[] = 'context_stack'; } Loading
src/ContextStackTrait.php +1 −1 Original line number Diff line number Diff line Loading @@ -213,7 +213,7 @@ trait ContextStackTrait { * Returns TRUE if available, FALSE otherwise. */ protected function contextStackCacheContextIsAvailable(): bool { return in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); return \Drupal::hasContainer() && in_array('context_stack', \Drupal::getContainer()->getParameter('cache_contexts')); } }