diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
index 5237d0d..98d87dd 100644
--- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
+++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
@@ -10,7 +10,10 @@
 use Drupal\Core\Executable\ExecutableManagerInterface;
 use Drupal\Core\Executable\ExecutablePluginBase;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
 use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Provides a basis for fulfilling contexts for condition plugins.
@@ -21,11 +24,20 @@
  *
  * @ingroup plugin_api
  */
-abstract class ConditionPluginBase extends ExecutablePluginBase implements ConditionInterface {
+abstract class ConditionPluginBase extends ExecutablePluginBase implements ConditionInterface, ContainerFactoryPluginInterface {
 
   use ContextAwarePluginAssignmentTrait;
 
   /**
+   * The context repository.
+   *
+   * @var \Drupal\Core\Plugin\Context\ContextRepositoryInterface|null
+   *
+   * @see self::getContextRepository()
+   */
+  protected $contextRepository;
+
+  /**
    * The condition manager to proxy execute calls through.
    *
    * @var \Drupal\Core\Executable\ExecutableInterface
@@ -33,17 +45,51 @@
   protected $executableManager;
 
   /**
-   * {@inheritdoc}
+   * Constructs a new instance.
+   *
+   * @param array $configuration
+   *   The plugin configuration.
+   * @param string $plugin_id
+   *   The plugin ID.
+   * @param mixed $plugin_definition
+   *   The plugin definition.
+   * @param \Drupal\Core\Plugin\Context\ContextRepositoryInterface|null $context_repository
+   *   The context repository (recommended), or NULL to have it located through
+   *   the service container automatically (deprecated).
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextRepositoryInterface $context_repository = NULL) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
-
+    $this->contextRepository = $context_repository;
     $this->setConfiguration($configuration);
   }
 
   /**
    * {@inheritdoc}
    */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    return new static($configuration, $plugin_id, $plugin_definition, $container->get('context.repository'));
+  }
+
+  /**
+   * Gets the context repository.
+   *
+   * @return \Drupal\Core\Plugin\Context\ContextRepositoryInterface
+   *
+   * @deprecated Deprecated as of Drupal 8.0.x, will be removed before Drupal
+   *   9.0.0. Inject the context repository through self::__construct() and
+   *   access self::$contextRepository directly instead.
+   */
+  protected function getContextRepository() {
+    if (!$this->contextRepository) {
+      $this->contextRepository = \Drupal::service('context.repository');
+    }
+
+    return $this->contextRepository;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
   public function isNegated() {
     return !empty($this->configuration['negate']);
   }
@@ -52,8 +98,22 @@ public function isNegated() {
    * {@inheritdoc}
    */
   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
-    $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
-    $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
+    // Retrieve the globally available contexts.
+    $contexts = $this->getContextRepository()->getAvailableContexts();
+    // Getting contexts from the form state is deprecated, as it means this
+    // implementation of
+    // \Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm() is not
+    // as reusable as the interface suggests. It is kept for compatibility with
+    // \Drupal\block\BlockForm.
+    // @todo Remove this before Drupal 9.0.0.
+    if ($form_state->hasTemporaryValue('gathered_contexts')) {
+      $contexts = array_merge($contexts, $form_state->getTemporaryValue('gathered_contexts'));
+    }
+    foreach ($contexts as $context_id => $context) {
+      $this->setContext($context_id, $context);
+    }
+
+    $form['context_mapping'] = $this->addContextAssignmentElement($this, $this->getContexts());
     $form['negate'] = array(
       '#type' => 'checkbox',
       '#title' => $this->t('Negate the condition'),
@@ -73,6 +133,9 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
    */
   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
     $this->configuration['negate'] = $form_state->getValue('negate');
+    if ($form_state->hasValue('context_mapping')) {
+      $this->setContextMapping($form_state->getValue('context_mapping'));
+    }
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php
index 6d7d609..a05fdaf 100644
--- a/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextRepositoryInterface.php
@@ -39,7 +39,7 @@ public function getRuntimeContexts(array $context_ids);
    * Gets all available contexts for the purposes of configuration.
    *
    * @return \Drupal\Core\Plugin\Context\ContextInterface[]
-   *   All available contexts.
+   *   All available contexts, keyed by context ID.
    */
   public function getAvailableContexts();
 
