diff --git a/src/Entity/Page.php b/src/Entity/Page.php
index 6782fc7..8c7e3d6 100644
--- a/src/Entity/Page.php
+++ b/src/Entity/Page.php
@@ -18,6 +18,10 @@ use Drupal\Core\Condition\ConditionPluginCollection;
 use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\page_manager\PageVariantInterface;
+use Drupal\ctools\ContextEnvironmentInterface;
+use Drupal\ctools\ContextEnvironmentTrait;
+use Drupal\ctools\ProvidedContextEnvironmentTrait;
+use Drupal\ctools\EnvironmentAwareContextRepository;
 
 /**
  * Defines a Page entity class.
@@ -46,7 +50,9 @@ use Drupal\page_manager\PageVariantInterface;
  *   },
  * )
  */
-class Page extends ConfigEntityBase implements PageInterface {
+class Page extends ConfigEntityBase implements PageInterface, ContextEnvironmentInterface {
+  use ContextEnvironmentTrait;
+  use ProvidedContextEnvironmentTrait;
 
   /**
    * The ID of the page entity.
@@ -86,9 +92,9 @@ class Page extends ConfigEntityBase implements PageInterface {
   /**
    * An array of collected contexts.
    *
-   * @var \Drupal\Component\Plugin\Context\ContextInterface[]
+   * @var \Drupal\Component\Plugin\Context\ContextRepositoryInterface
    */
-  protected $contexts = [];
+  protected $context_repository = NULL ;
 
   /**
    * The configuration of access conditions.
@@ -274,9 +280,9 @@ class Page extends ConfigEntityBase implements PageInterface {
       'type' => $type,
       'label' => $label,
     ];
-    // Reset contexts when a parameter is added or changed.
-    $this->contexts = [];
-    // Reset the contexts of every variant.
+    // Reset context repository when a parameter is added or changed.
+    $this->context_repository = NULL;
+    // Reset the context repository of every variant.
     foreach ($this->getVariants() as $page_variant) {
       $page_variant->resetCollectedContexts();
     }
@@ -288,9 +294,9 @@ class Page extends ConfigEntityBase implements PageInterface {
    */
   public function removeParameter($name) {
     unset($this->parameters[$name]);
-    // Reset contexts when a parameter is removed.
-    $this->contexts = [];
-    // Reset the contexts of every variant.
+    // Reset context respository when a parameter is removed.
+    $this->context_repository = NULL;
+    // Reset the context repository of every variant.
     foreach ($this->getVariants() as $page_variant) {
       $page_variant->resetCollectedContexts();
     }
@@ -336,6 +342,7 @@ class Page extends ConfigEntityBase implements PageInterface {
    * {@inheritdoc}
    */
   public function addContext($name, ContextInterface $value) {
+    $this->setContext($name, $value);
     $this->contexts[$name] = $value;
   }
 
@@ -343,38 +350,20 @@ class Page extends ConfigEntityBase implements PageInterface {
    * {@inheritdoc}
    */
   public function getContexts() {
-    // @todo add the other global contexts here as they are added
-    // @todo maybe come up with a non-hardcoded way of doing this?
-    $global_contexts = [
-      'current_user'
-    ];
-    if (!$this->contexts) {
-      $this->eventDispatcher()->dispatch(PageManagerEvents::PAGE_CONTEXT, new PageManagerContextEvent($this));
-      foreach ($this->getParameters() as $machine_name => $configuration) {
-        // Parameters can be updated in the UI, so unless it's a global context
-        // we'll need to rely on the current settings in the tempstore instead
-        // of the ones cached in the router.
-        if (!isset($global_contexts[$machine_name])) {
-          // First time through, parameters will not be defined by the route.
-          if (!isset($this->contexts[$machine_name])) {
-            $cacheability = new CacheableMetadata();
-            $cacheability->setCacheContexts(['route']);
-
-            $context_definition = new ContextDefinition($configuration['type'], $configuration['label']);
-            $context = new Context($context_definition);
-            $context->addCacheableDependency($cacheability);
-            $this->contexts[$machine_name] = $context;
-          }
-          else {
-            $this->contexts[$machine_name]->getContextDefinition()->setDataType($configuration['type']);
-            if (!empty($configuration['label'])) {
-              $this->contexts[$machine_name]->getContextDefinition()->setLabel($configuration['label']);
-            }
-          }
-        }
-      }
+    $available = $this->getContextRepository()->getAvailableContexts() ? : [];
+    $runtime = $this->getContextRepository()->getRuntimeContexts(array_keys($available));
+    return $runtime + $available;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getAvailableProvidedContexts() {
+    $available_contexts = [];
+    foreach ($this->getParameters() as $machine_name => $configuration) {
+      $available_contexts[$machine_name] = new Context(new ContextDefinition($configuration['type'], $configuration['label']));
     }
-    return $this->contexts;
+    return $available_contexts;
   }
 
   /**
@@ -465,8 +454,8 @@ class Page extends ConfigEntityBase implements PageInterface {
   public function __sleep() {
     $vars = parent::__sleep();
 
-    // Gathered contexts objects should not be serialized.
-    if (($key = array_search('contexts', $vars)) !== FALSE) {
+    // Context repository objects should not be serialized.
+    if (($key = array_search('context_repository', $vars)) !== FALSE) {
       unset($vars[$key]);
     }
 
@@ -489,4 +478,17 @@ class Page extends ConfigEntityBase implements PageInterface {
     return parent::urlRouteParameters($rel);
   }
 
+  /**
+   * Get the context repository.
+   *
+   * @return \Drupal\Component\Plugin\Context\ContextRepositoryInterface
+   */
+  public function getContextRepository() {
+    if (!$this->context_repository) {
+      $this->context_repository = new EnvironmentAwareContextRepository();
+      $this->context_repository->addContextEnvironment('page', $this);
+    }
+
+    return $this->context_repository;
+  }
 }
diff --git a/src/Entity/PageVariant.php b/src/Entity/PageVariant.php
index 58ad7f8..59da71d 100644
--- a/src/Entity/PageVariant.php
+++ b/src/Entity/PageVariant.php
@@ -13,6 +13,10 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;
+use Drupal\ctools\ContextEnvironmentInterface;
+use Drupal\ctools\ContextEnvironmentTrait;
+use Drupal\ctools\ConfigurableStaticContextEnvironmentTrait;
+use Drupal\ctools\EnvironmentAwareContextRepository;
 use Drupal\page_manager\PageInterface;
 use Drupal\page_manager\PageVariantInterface;
 
@@ -49,7 +53,9 @@ use Drupal\page_manager\PageVariantInterface;
  *   }
  * )
  */
-class PageVariant extends ConfigEntityBase implements PageVariantInterface {
+class PageVariant extends ConfigEntityBase implements PageVariantInterface, ContextEnvironmentInterface {
+  use ConfigurableStaticContextEnvironmentTrait;
+  use ContextEnvironmentTrait;
 
   /**
    * The ID of the page variant entity.
@@ -122,11 +128,11 @@ class PageVariant extends ConfigEntityBase implements PageVariantInterface {
   protected $selection_logic = 'and';
 
   /**
-   * An array of collected contexts.
+   * The context repository object.
    *
-   * @var \Drupal\Component\Plugin\Context\ContextInterface[]|null
+   * @var \Drupal\Component\Plugin\Context\ContextRepositoryInterface
    */
-  protected $contexts = NULL;
+  protected $context_repository;
 
   /**
    * Static context references.
@@ -280,19 +286,31 @@ class PageVariant extends ConfigEntityBase implements PageVariantInterface {
    * {@inheritdoc}
    */
   public function getContexts() {
-    if (is_null($this->contexts)) {
-      $static_contexts = $this->getContextMapper()->getContextValues($this->getStaticContexts());
-      $page_contexts = $this->getPage()->getContexts();
-      $this->contexts = $page_contexts + $static_contexts;
+    $available = $this->getContextRepository()->getAvailableContexts() ? : [];
+    $runtime = $this->getContextRepository()->getRuntimeContexts(array_keys($available));
+    return $runtime + $available;
+  }
+
+  /**
+   * Get the context repository.
+   *
+   * @return \Drupal\Core\Context\ContextRepositoryInterface
+   */
+  public function getContextRepository() {
+    if (!$this->context_repository) {
+      $this->context_repository = new EnvironmentAwareContextRepository();
+      $this->context_repository->addContextEnvironment('page', $this->getPage());
+      $this->context_repository->addContextEnvironment('page_variant', $this);
     }
-    return $this->contexts;
+
+    return $this->context_repository;
   }
 
   /**
    * {@inheritdoc}
    */
   public function resetCollectedContexts() {
-    $this->contexts = NULL;
+    $this->context_repository = NULL;
     return $this;
   }
 
@@ -462,8 +480,8 @@ class PageVariant extends ConfigEntityBase implements PageVariantInterface {
   public function __sleep() {
     $vars = parent::__sleep();
 
-    // Gathered contexts objects should not be serialized.
-    if (($key = array_search('contexts', $vars)) !== FALSE) {
+    // Context repository should not be serialized.
+    if (($key = array_search('context_repository', $vars)) !== FALSE) {
       unset($vars[$key]);
     }
 
