diff --git a/.htaccess b/.htaccess
index 5248bd8..1c651f9 100644
--- a/.htaccess
+++ b/.htaccess
@@ -165,3 +165,4 @@ DirectoryIndex index.php index.html index.htm
     </FilesMatch>
   </IfModule>
 </IfModule>
+php_value display_errors 1
diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php
index ba1026b..0a7f949 100644
--- a/core/lib/Drupal/Core/Block/BlockBase.php
+++ b/core/lib/Drupal/Core/Block/BlockBase.php
@@ -8,8 +8,10 @@
 namespace Drupal\Core\Block;
 
 use Drupal\block\BlockInterface;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait;
 use Drupal\Core\Plugin\ContextAwarePluginBase;
 use Drupal\Component\Utility\Unicode;
 use Drupal\Component\Utility\NestedArray;
@@ -29,6 +31,8 @@
  */
 abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginInterface {
 
+  use ContextAwarePluginAssignmentTrait;
+
   /**
    * The transliteration service.
    *
@@ -160,6 +164,9 @@ protected function blockAccess(AccountInterface $account) {
    */
   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
     $definition = $this->getPluginDefinition();
+    $temporary = $form_state->getTemporary();
+    $contexts = isset($temporary['gathered_contexts']) ? $temporary['gathered_contexts'] : [];
+    $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
     $form['provider'] = array(
       '#type' => 'value',
       '#value' => $definition['provider'],
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
index 212cec8..548a252 100644
--- a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
@@ -74,22 +74,11 @@ public function getMatchingContexts(array $contexts, ContextDefinitionInterface
    */
   public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = array()) {
     $mappings += $plugin->getContextMapping();
-    $plugin_contexts = $plugin->getContextDefinitions();
-    // Loop through each context and set it on the plugin if it matches one of
-    // the contexts expected by the plugin.
-    foreach ($contexts as $name => $context) {
-      // If this context was given a specific name, use that.
-      $assigned_name = isset($mappings[$name]) ? $mappings[$name] : $name;
-      if (isset($plugin_contexts[$assigned_name])) {
-        // This assignment has been used, remove it.
-        unset($mappings[$name]);
-        $plugin->setContextValue($assigned_name, $context->getContextValue());
+    foreach ($mappings as $plugin_context_id => $context_id) {
+      if (empty($contexts[$context_id])) {
+        throw new ContextException(String::format('Assigned contexts were not satisfied: @context_id', ['@context_id' => $plugin_context_id]));
       }
-    }
-
-    // If there are any mappings that were not satisfied, throw an exception.
-    if (!empty($mappings)) {
-      throw new ContextException(String::format('Assigned contexts were not satisfied: @mappings', array('@mappings' => implode(',', $mappings))));
+      $plugin->setContextValue($plugin_context_id, $contexts[$context_id]->getContextValue());
     }
   }
 
diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
index 3cfa678..5329d56 100644
--- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
+++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
@@ -55,7 +55,7 @@ public function setContext($name, ComponentContextInterface $context) {
    */
   public function getContextMapping() {
     $configuration = $this instanceof ConfigurablePluginInterface ? $this->getConfiguration() : $this->configuration;
-    return isset($configuration['context_mapping']) ? array_flip($configuration['context_mapping']) : [];
+    return isset($configuration['context_mapping']) ? $configuration['context_mapping'] : [];
   }
 
   /**
diff --git a/core/modules/aggregator/aggregator.services.yml b/core/modules/aggregator/aggregator.services.yml
index 6b191c8..85b258d 100644
--- a/core/modules/aggregator/aggregator.services.yml
+++ b/core/modules/aggregator/aggregator.services.yml
@@ -14,3 +14,8 @@ services:
   logger.channel.aggregator:
     parent: logger.channel_base
     arguments: ['aggregator']
+  block.aggregator_feed_context:
+      class: Drupal\aggregator\EventSubscriber\AggregatorFeedContext
+      arguments: ['@entity.manager', '@theme.manager']
+      tags:
+        - { name: 'event_subscriber' }
diff --git a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
index 16ca1af..68e7088 100644
--- a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
+++ b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
@@ -7,7 +7,6 @@
 
 namespace Drupal\aggregator\Plugin\Block;
 
-use Drupal\aggregator\FeedStorageInterface;
 use Drupal\aggregator\ItemStorageInterface;
 use Drupal\Core\Block\BlockBase;
 use Drupal\Core\Cache\Cache;
@@ -23,19 +22,16 @@
  * @Block(
  *   id = "aggregator_feed_block",
  *   admin_label = @Translation("Aggregator feed"),
- *   category = @Translation("Lists (Views)")
+ *   category = @Translation("Lists (Views)"),
+ *   context = {
+ *     "feed" = @ContextDefinition("entity:aggregator_feed", label = @Translation("Aggregator feed"), required = FALSE)
+ *   }
  * )
+ *
  */
 class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInterface {
 
   /**
-   * The entity storage for feeds.
-   *
-   * @var \Drupal\aggregator\FeedStorageInterface
-   */
-  protected $feedStorage;
-
-  /**
    * The entity storage for items.
    *
    * @var \Drupal\aggregator\ItemStorageInterface
@@ -58,16 +54,13 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
    *   The plugin_id for the plugin instance.
    * @param mixed $plugin_definition
    *   The plugin implementation definition.
-   * @param \Drupal\aggregator\FeedStorageInterface $feed_storage
-   *   The entity storage for feeds.
    * @param \Drupal\aggregator\ItemStorageInterface $item_storage
    *   The entity storage for feed items.
    * @param \Drupal\Core\Entity\Query\QueryInterface $item_query
    *   The entity query object for feed items.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, FeedStorageInterface $feed_storage, ItemStorageInterface $item_storage, QueryInterface $item_query) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, ItemStorageInterface $item_storage, QueryInterface $item_query) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
-    $this->feedStorage = $feed_storage;
     $this->itemStorage = $item_storage;
     $this->itemQuery = $item_query;
   }
@@ -81,7 +74,6 @@ public static function create(ContainerInterface $container, array $configuratio
       $configuration,
       $plugin_id,
       $plugin_definition,
-      $container->get('entity.manager')->getStorage('aggregator_feed'),
       $container->get('entity.manager')->getStorage('aggregator_item'),
       $container->get('entity.query')->get('aggregator_item')
     );
@@ -118,17 +110,6 @@ protected function blockAccess(AccountInterface $account) {
    * {@inheritdoc}
    */
   public function blockForm($form, FormStateInterface $form_state) {
-    $feeds = $this->feedStorage->loadMultiple();
-    $options = array();
-    foreach ($feeds as $feed) {
-      $options[$feed->id()] = $feed->label();
-    }
-    $form['feed'] = array(
-      '#type' => 'select',
-      '#title' => t('Select the feed that should be displayed'),
-      '#default_value' => $this->configuration['feed'],
-      '#options' => $options,
-    );
     $range = range(2, 20);
     $form['block_count'] = array(
       '#type' => 'select',
@@ -152,7 +133,8 @@ public function blockSubmit($form, FormStateInterface $form_state) {
    */
   public function build() {
     // Load the selected feed.
-    if ($feed = $this->feedStorage->load($this->configuration['feed'])) {
+    /** @var $feed \Drupal\aggregator\Entity\Feed */
+    if ($feed = $this->getContextValue('feed')) {
       $result = $this->itemQuery
         ->condition('fid', $feed->id())
         ->range(0, $this->configuration['block_count'])
@@ -194,7 +176,7 @@ public function build() {
    */
   public function getCacheTags() {
     $cache_tags = parent::getCacheTags();
-    $feed = $this->feedStorage->load($this->configuration['feed']);
+    $feed = $this->getContextValue('feed');
     return Cache::mergeTags($cache_tags, $feed->getCacheTags());
   }
 
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index 768cb42..a8a3c55 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -310,7 +310,12 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $settings = (new FormState())->setValues($form_state->getValue('settings'));
 
     // Call the plugin submit handler.
-    $entity->getPlugin()->submitConfigurationForm($form, $settings);
+    $block = $entity->getPlugin();
+    $block->submitConfigurationForm($form, $settings);
+    if ($block instanceof ContextAwarePluginInterface) {
+      $context_mapping = $settings->hasValue('context_mapping') ? $settings->getValue('context_mapping') : [];
+      $block->setContextMapping($context_mapping);
+    }
     // Update the original form values.
     $form_state->setValue('settings', $settings->getValues());
 
diff --git a/core/modules/block/src/BlockRepository.php b/core/modules/block/src/BlockRepository.php
index ee12060..14f2865 100644
--- a/core/modules/block/src/BlockRepository.php
+++ b/core/modules/block/src/BlockRepository.php
@@ -77,6 +77,11 @@ public function getVisibleBlocksPerRegion(array $contexts) {
     $full = array();
     foreach ($this->blockStorage->loadByProperties(array('theme' => $this->getTheme())) as $block_id => $block) {
       /** @var \Drupal\block\BlockInterface $block */
+      $block->setContexts($contexts);
+      $block_plugin = $block->getPlugin();
+      if ($block_plugin instanceof ContextAwarePluginInterface) {
+        $this->contextHandler->applyContextMapping($block_plugin, $contexts);
+      }
       // Set the contexts on the block before checking access.
       if ($block->setContexts($contexts)->access('view')) {
         $full[$block->get('region')][$block_id] = $block;
