diff --git a/page_manager_ui/src/Form/PageVariantContextsForm.php b/page_manager_ui/src/Form/PageVariantContextsForm.php
index d48c138..5a8af17 100644
--- a/page_manager_ui/src/Form/PageVariantContextsForm.php
+++ b/page_manager_ui/src/Form/PageVariantContextsForm.php
@@ -89,7 +89,7 @@ class PageVariantContextsForm extends ManageContext {
   protected function getContexts($cached_values) {
     /** @var $page_variant \Drupal\page_manager\Entity\PageVariant */
     $page_variant = $cached_values['page_variant'];
-    return $page_variant->getContexts();
+    return $page_variant->getContextRepository()->getAvailableContexts();
   }
 
   /**
diff --git a/page_manager_ui/src/Form/StaticContextConfigure.php b/page_manager_ui/src/Form/StaticContextConfigure.php
index bfc8edf..661f0ef 100644
--- a/page_manager_ui/src/Form/StaticContextConfigure.php
+++ b/page_manager_ui/src/Form/StaticContextConfigure.php
@@ -79,7 +79,7 @@ class StaticContextConfigure extends ContextConfigure {
     if (is_null($page_variant)) {
       $page_variant = $this->getPageVariant($cached_values);
     }
-    return $page_variant->getContexts();
+    return $page_variant->getContextRepository()->getAvailableContexts();
   }
 
   /**
diff --git a/src/Entity/Page.php b/src/Entity/Page.php
index 6782fc7..95f2ae4 100644
--- a/src/Entity/Page.php
+++ b/src/Entity/Page.php
@@ -18,6 +18,8 @@ use Drupal\Core\Condition\ConditionPluginCollection;
 use Drupal\Core\Config\Entity\ConfigEntityBase;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\page_manager\PageVariantInterface;
+use Drupal\ctools\EnvironmentWithProvidedContextInterface;
+use Drupal\ctools\EnvironmentProvidedContextProvider;
 
 /**
  * Defines a Page entity class.
@@ -46,7 +48,7 @@ use Drupal\page_manager\PageVariantInterface;
  *   },
  * )
  */
-class Page extends ConfigEntityBase implements PageInterface {
+class Page extends ConfigEntityBase implements PageInterface, EnvironmentWithProvidedContextInterface {
 
   /**
    * The ID of the page entity.
@@ -86,9 +88,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 +276,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 +290,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();
     }
@@ -342,39 +344,28 @@ class Page extends ConfigEntityBase implements PageInterface {
   /**
    * {@inheritdoc}
    */
+  public function getContext($name) {
+    return $this->contexts[$name];
+  }
+
+  /**
+   * {@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 getContextDefinitions() {
+    $definitions = [];
+    foreach ($this->getParameters() as $machine_name => $configuration) {
+      $definitions[$machine_name] = new ContextDefinition($configuration['type'], $configuration['label']);
     }
-    return $this->contexts;
+    return $definitions;
   }
 
   /**
@@ -465,8 +456,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 +480,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 = \Drupal::service('ctools.environment_context_repository_factory')
+        ->getContextRepository(['page' => new EnvironmentProvidedContextProvider($this)]);
+    }
+
+    return $this->context_repository;
+  }
 }
diff --git a/src/Entity/PageVariant.php b/src/Entity/PageVariant.php
index 58ad7f8..c52d14e 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\EnvironmentRelationshipContextProvider;
+use Drupal\ctools\EnvironmentStaticContextProvider;
+use Drupal\ctools\EnvironmentWithStaticContextInterface;
+use Drupal\ctools\EnvironmentWithRelationshipContextInterface;
 use Drupal\page_manager\PageInterface;
 use Drupal\page_manager\PageVariantInterface;
 
@@ -43,13 +47,14 @@ use Drupal\page_manager\PageVariantInterface;
  *     "selection_criteria",
  *     "selection_logic",
  *     "static_context",
+ *     "relationship_context",
  *   },
  *   lookup_keys = {
  *     "page"
  *   }
  * )
  */
-class PageVariant extends ConfigEntityBase implements PageVariantInterface {
+class PageVariant extends ConfigEntityBase implements PageVariantInterface, EnvironmentWithStaticContextInterface, EnvironmentWithRelationshipContextInterface {
 
   /**
    * The ID of the page variant entity.
@@ -122,11 +127,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.
@@ -138,6 +143,15 @@ class PageVariant extends ConfigEntityBase implements PageVariantInterface {
   protected $static_context = [];
 
   /**
+   * Relationship context references.
+   *
+   * A list of arrays.
+   *
+   * @var array[]
+   */
+  protected $relationship_context = [];
+
+  /**
    * The plugin collection that holds the single variant plugin instance.
    *
    * @var \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection
@@ -280,19 +294,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 = $this->getPage()->getContextRepository();
+      $this->context_repository->addEnvironmentContextProvider('static', new EnvironmentStaticContextProvider($this));
+      $this->context_repository->addEnvironmentContextProvider('rel', new EnvironmentRelationshipContextProvider($this));
     }
-    return $this->contexts;
+
+    return $this->context_repository;
   }
 
   /**
    * {@inheritdoc}
    */
   public function resetCollectedContexts() {
-    $this->contexts = NULL;
+    $this->context_repository = NULL;
     return $this;
   }
 
@@ -397,6 +423,41 @@ class PageVariant extends ConfigEntityBase implements PageVariantInterface {
   /**
    * {@inheritdoc}
    */
+  public function getRelationships() {
+    return $this->relationship_context;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRelationship($name) {
+    if (isset($this->relationship_context[$name])) {
+      return $this->relationship_context[$name];
+    }
+    return [];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRelationship($name, $configuration) {
+    $this->relationship_context[$name] = $configuration;
+    $this->resetCollectedContexts();
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function removeRelationship($name) {
+    unset($this->relationship_context[$name]);
+    $this->resetCollectedContexts();
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   protected function urlRouteParameters($rel) {
     $parameters = parent::urlRouteParameters($rel);
     $parameters['page'] = $this->get('page');
@@ -462,8 +523,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]);
     }
 
