diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml
index 2b86cd7..ec1d462 100644
--- a/core/config/schema/core.data_types.schema.yml
+++ b/core/config/schema/core.data_types.schema.yml
@@ -289,6 +289,31 @@ block_settings:
     view_mode:
       type: string
       label: 'View mode'
+    visibility:
+      type: sequence
+      label: 'Visibility Conditions'
+      sequence:
+        - type: condition.plugin.[id]
+          label: 'Visibility Condition'
     provider:
       type: string
       label: 'Provider'
+
+condition.plugin:
+  type: mapping
+  label: 'Condition'
+  mapping:
+    id:
+      type: string
+      label: 'ID'
+    negate:
+      type: boolean
+      label: 'Negate'
+    uuid:
+      type: string
+      label: 'UUID'
+    context_assignments:
+      type: sequence
+      label: 'Context assignments'
+      sequence:
+        - type: string
diff --git a/core/core.services.yml b/core/core.services.yml
index d0facb4..9466f95 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -115,6 +115,9 @@ services:
   config.typed:
     class: Drupal\Core\Config\TypedConfigManager
     arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery']
+  context.handler:
+    class: Drupal\Core\Plugin\Context\ContextHandler
+    arguments: ['@typed_data_manager']
   cron:
     class: Drupal\Core\Cron
     arguments: ['@module_handler', '@lock', '@queue', '@state', '@current_user', '@session_manager']
diff --git a/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php b/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php
new file mode 100644
index 0000000..f5723e8
--- /dev/null
+++ b/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php
@@ -0,0 +1,76 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Condition\ConditionAccessResolverTrait.
+ */
+
+namespace Drupal\Core\Condition;
+
+use Drupal\Component\Plugin\ConfigurablePluginInterface;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
+use Drupal\Component\Plugin\Exception\PluginException;
+
+/**
+ * Resolves a set of conditions.
+ */
+trait ConditionAccessResolverTrait {
+
+  /**
+   * Wraps the context handler.
+   *
+   * @return \Drupal\Core\Plugin\Context\ContextHandlerInterface
+   */
+  protected function contextHandler() {
+    return \Drupal::service('context.handler');
+  }
+
+  /**
+   * Resolves the given conditions based on the condition logic ('and'/'or').
+   *
+   * @param \Drupal\Core\Condition\ConditionInterface[] $conditions
+   *   A set of conditions.
+   * @param string $condition_logic
+   *   The logic used to compute access, either 'and' or 'or'.
+   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
+   *   (optional) An array of contexts to set on the conditions.
+   *
+   * @return bool
+   *   Whether these conditions grant or deny access.
+   */
+  protected function resolveConditions($conditions, $condition_logic, $contexts = array()) {
+    foreach ($conditions as $condition) {
+      if ($condition instanceof ContextAwarePluginInterface) {
+        $assignments = array();
+        if ($condition instanceof ConfigurablePluginInterface) {
+          $configuration = $condition->getConfiguration();
+          if (isset($configuration['context_assignments'])) {
+            $assignments = array_flip($configuration['context_assignments']);
+          }
+        }
+        $this->contextHandler()->applyContextMapping($condition, $contexts, $assignments);
+      }
+
+      try {
+        $pass = $condition->execute();
+      }
+      catch (PluginException $e) {
+        // If a condition is missing context, consider that a fail.
+        $pass = FALSE;
+      }
+
+      // If a condition fails and all conditions were required, deny access.
+      if (!$pass && $condition_logic == 'and') {
+        return FALSE;
+      }
+      // If a condition passes and one condition was required, grant access.
+      elseif ($pass && $condition_logic == 'or') {
+        return TRUE;
+      }
+    }
+
+    // If no conditions passed and one condition was required, deny access.
+    return $condition_logic == 'and';
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php
index 4b4e659..ca24add 100644
--- a/core/lib/Drupal/Core/Condition/ConditionManager.php
+++ b/core/lib/Drupal/Core/Condition/ConditionManager.php
@@ -12,6 +12,7 @@
 use Drupal\Core\Executable\ExecutableInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Language\LanguageManager;
+use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait;
 use Drupal\Core\Plugin\DefaultPluginManager;
 
 /**
@@ -19,6 +20,8 @@
  */
 class ConditionManager extends DefaultPluginManager implements ExecutableManagerInterface {
 
+  use ContextAwarePluginManagerTrait;
+
   /**
    * Constructs a ConditionManager object.
    *
diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBag.php b/core/lib/Drupal/Core/Condition/ConditionPluginBag.php
new file mode 100644
index 0000000..b15f302
--- /dev/null
+++ b/core/lib/Drupal/Core/Condition/ConditionPluginBag.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Condition\ConditionPluginBag.
+ */
+
+namespace Drupal\Core\Condition;
+
+use Drupal\Core\Plugin\DefaultPluginBag;
+
+/**
+ * Provides a collection of condition plugins.
+ */
+class ConditionPluginBag extends DefaultPluginBag {
+
+  /**
+   * {@inheritdoc}
+   *
+   * @return \Drupal\Core\Condition\ConditionInterface
+   */
+  public function &get($instance_id) {
+    return parent::get($instance_id);
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
index 2f250ba..279ef0f 100644
--- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
+++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
@@ -37,7 +37,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
     $form['negate'] = array(
       '#type' => 'checkbox',
       '#title' => $this->t('Negate the condition.'),
-      '#default_value' => isset($this->configuration['negate']) ? $this->configuration['negate'] : FALSE,
+      '#default_value' => $this->configuration['negate'],
     );
     return $form;
   }
@@ -83,7 +83,9 @@ public function setConfiguration(array $configuration) {
    * {@inheritdoc}
    */
   public function defaultConfiguration() {
-    return array();
+    return array(
+      'negate' => FALSE,
+    );
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerInterface.php
new file mode 100644
index 0000000..7bf137d
--- /dev/null
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerInterface.php
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface.
+ */
+
+namespace Drupal\Core\Plugin\Context;
+
+use Drupal\Component\Plugin\PluginManagerInterface;
+
+/**
+ * Provides an interface for plugin managers that support context-aware plugins.
+ */
+interface ContextAwarePluginManagerInterface extends PluginManagerInterface {
+
+  /**
+   * Determines plugins whose constraints are satisfied by a set of contexts.
+   *
+   * @todo Use context definition objects after https://drupal.org/node/2281635.
+   *
+   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
+   *   An array of contexts.
+   *
+   * @return array
+   *   An array of plugin definitions.
+   */
+  public function getDefinitionsForContexts(array $contexts = array());
+
+}
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php b/core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php
new file mode 100644
index 0000000..407b789
--- /dev/null
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextAwarePluginManagerTrait.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait.
+ */
+
+namespace Drupal\Core\Plugin\Context;
+
+/**
+ * Provides a trait for plugin managers that support context-aware plugins.
+ */
+trait ContextAwarePluginManagerTrait {
+
+  /**
+   * Wraps the context handler.
+   *
+   * @return \Drupal\Core\Plugin\Context\ContextHandlerInterface
+   */
+  protected function contextHandler() {
+    return \Drupal::service('context.handler');
+  }
+
+  /**
+   * See \Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface::getDefinitionsForContexts().
+   */
+  public function getDefinitionsForContexts(array $contexts = array()) {
+    return $this->contextHandler()->filterPluginDefinitionsByContexts($contexts, $this->getDefinitions());
+  }
+
+  /**
+   * See \Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
+   */
+  abstract public function getDefinitions();
+
+}
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
new file mode 100644
index 0000000..68fbda3
--- /dev/null
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
@@ -0,0 +1,144 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Plugin\Context\ContextHandler.
+ */
+
+namespace Drupal\Core\Plugin\Context;
+
+use Drupal\Component\Plugin\Context\ContextInterface;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
+use Drupal\Component\Plugin\Exception\ContextException;
+use Drupal\Component\Utility\String;
+use Drupal\Core\TypedData\DataDefinitionInterface;
+use Drupal\Core\TypedData\DataDefinition;
+use Drupal\Core\TypedData\TypedDataManager;
+
+/**
+ * Provides methods to handle sets of contexts.
+ */
+class ContextHandler implements ContextHandlerInterface {
+
+  /**
+   * The typed data manager.
+   *
+   * @var \Drupal\Core\TypedData\TypedDataManager
+   */
+  protected $typedDataManager;
+
+  /**
+   * Constructs a new ContextHandler.
+   *
+   * @param \Drupal\Core\TypedData\TypedDataManager $typed_data
+   *   The typed data manager.
+   */
+  public function __construct(TypedDataManager $typed_data) {
+    $this->typedDataManager = $typed_data;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function filterPluginDefinitionsByContexts(array $contexts, array $definitions) {
+    return array_filter($definitions, function ($plugin_definition) use ($contexts) {
+      // If this plugin doesn't need any context, it is available to use.
+      if (!isset($plugin_definition['context'])) {
+        return TRUE;
+      }
+
+      // Build an array of requirements out of the contexts specified by the
+      // plugin definition.
+      $requirements = array();
+      foreach ($plugin_definition['context'] as $context_id => $plugin_context) {
+        $definition = $this->typedDataManager->getDefinition($plugin_context['type']);
+        $definition['type'] = $plugin_context['type'];
+
+        // If the plugin specifies additional constraints, add them to the
+        // constraints defined by the plugin type.
+        if (isset($plugin_context['constraints'])) {
+          // Ensure the array exists before adding in constraints.
+          if (!isset($definition['constraints'])) {
+            $definition['constraints'] = array();
+          }
+
+          $definition['constraints'] += $plugin_context['constraints'];
+        }
+
+        // Assume the requirement is required if unspecified.
+        if (!isset($definition['required'])) {
+          $definition['required'] = TRUE;
+        }
+
+        // @todo Use context definition objects after
+        //   https://drupal.org/node/2281635.
+        $requirements[$context_id] = new DataDefinition($definition);
+      }
+
+      // Check the set of contexts against the requirements.
+      return $this->checkRequirements($contexts, $requirements);
+    });
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function checkRequirements(array $contexts, array $requirements) {
+    foreach ($requirements as $requirement) {
+      if ($requirement->isRequired() && !$this->getMatchingContexts($contexts, $requirement)) {
+        return FALSE;
+      }
+    }
+    return TRUE;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getMatchingContexts(array $contexts, DataDefinitionInterface $definition) {
+    return array_filter($contexts, function (ContextInterface $context) use ($definition) {
+      // @todo getContextDefinition() should return a DataDefinitionInterface.
+      $context_definition = new DataDefinition($context->getContextDefinition());
+
+      // If the data types do not match, this context is invalid.
+      if ($definition->getDataType() != $context_definition->getDataType()) {
+        return FALSE;
+      }
+
+      // If any constraint does not match, this context is invalid.
+      // @todo This is too restrictive, consider only relying on data types.
+      foreach ($definition->getConstraints() as $constraint_name => $constraint) {
+        if ($context_definition->getConstraint($constraint_name) != $constraint) {
+          return FALSE;
+        }
+      }
+
+      // All contexts with matching data type and contexts are valid.
+      return TRUE;
+    });
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = array()) {
+    $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());
+      }
+    }
+
+    // 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))));
+    }
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php
new file mode 100644
index 0000000..b39df2c
--- /dev/null
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Plugin\Context\ContextHandlerInterface.
+ */
+
+namespace Drupal\Core\Plugin\Context;
+
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
+use Drupal\Core\TypedData\DataDefinitionInterface;
+
+/**
+ * Provides an interface for handling sets of contexts.
+ */
+interface ContextHandlerInterface {
+
+  /**
+   * Determines plugins whose constraints are satisfied by a set of contexts.
+   *
+   * @todo Use context definition objects after https://drupal.org/node/2281635.
+   *
+   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
+   *   An array of contexts.
+   * @param array $definitions .
+   *   An array of plugin definitions.
+   *
+   * @return array
+   *   An array of plugin definitions.
+   */
+  public function filterPluginDefinitionsByContexts(array $contexts, array $definitions);
+
+  /**
+   * Checks a set of requirements against a set of contexts.
+   *
+   * @todo Use context definition objects after https://drupal.org/node/2281635.
+   *
+   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
+   *   An array of available contexts.
+   * @param \Drupal\Core\TypedData\DataDefinitionInterface[] $requirements
+   *   An array of requirements.
+   *
+   * @return bool
+   *   TRUE if all of the requirements are satisfied by the context, FALSE
+   *   otherwise.
+   */
+  public function checkRequirements(array $contexts, array $requirements);
+
+  /**
+   * Determines which contexts satisfy the constraints of a given definition.
+   *
+   * @todo Use context definition objects after https://drupal.org/node/2281635.
+   *
+   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
+   *   An array of contexts.
+   * @param \Drupal\Core\TypedData\DataDefinitionInterface $definition
+   *   The definition to satisfy.
+   *
+   * @return \Drupal\Component\Plugin\Context\ContextInterface[]
+   *   An array of matching contexts.
+   */
+  public function getMatchingContexts(array $contexts, DataDefinitionInterface $definition);
+
+  /**
+   * Prepares a plugin for evaluation.
+   *
+   * @param \Drupal\Component\Plugin\ContextAwarePluginInterface $plugin
+   *   A plugin about to be evaluated.
+   * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
+   *   An array of contexts to set on the plugin. They will only be set if they
+   *   match the plugin's context definitions.
+   * @param array $mappings
+   *   (optional) A mapping of the expected assignment names to their context
+   *   names. For example, if one of the $contexts is named 'entity', but the
+   *   plugin expects a context named 'node', then this map would contain
+   *   'entity' => 'node'.
+   *
+   * @throws \Drupal\Component\Plugin\Exception\ContextException
+   *   Thrown when a context assignment was not satisfied.
+   */
+  public function applyContextMapping(ContextAwarePluginInterface $plugin, $contexts, $mappings = array());
+
+}
diff --git a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
index 5fdc33a..4381b6d 100644
--- a/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
+++ b/core/modules/aggregator/src/Plugin/Block/AggregatorFeedBlock.php
@@ -100,7 +100,7 @@ public function defaultConfiguration() {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     // Only grant access to users with the 'access news feeds' permission.
     return $account->hasPermission('access news feeds');
   }
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index ceffa1f..db363dd 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -12,22 +12,6 @@
 use Symfony\Component\HttpFoundation\Request;
 
 /**
- * Shows this block on every page except the listed pages.
- */
-const BLOCK_VISIBILITY_NOTLISTED = 0;
-
-/**
- * Shows this block on only the listed pages.
- */
-const BLOCK_VISIBILITY_LISTED = 1;
-
-/**
- * Shows this block if the associated PHP code returns TRUE.
- */
-const BLOCK_VISIBILITY_PHP = 2;
-
-
-/**
  * Implements hook_help().
  */
 function block_help($route_name, Request $request) {
@@ -391,10 +375,12 @@ function template_preprocess_block(&$variables) {
  */
 function block_user_role_delete($role) {
   foreach (entity_load_multiple('block') as $block) {
-    $visibility = $block->get('visibility');
+    /** @var $block \Drupal\block\BlockInterface */
+    $visibility_conditions = $block->getPlugin()->getVisibilityConditions();
+    $visibility = $visibility_conditions->getConfiguration();
     if (isset($visibility['roles']['roles'][$role->id()])) {
       unset($visibility['roles']['roles'][$role->id()]);
-      $block->set('visibility', $visibility);
+      $visibility_conditions->setConfiguration($visibility);
       $block->save();
     }
   }
@@ -421,10 +407,12 @@ function block_menu_delete(Menu $menu) {
 function block_language_entity_delete(Language $language) {
   // Remove the block visibility settings for the deleted language.
   foreach (entity_load_multiple('block') as $block) {
-    $visibility = $block->get('visibility');
+    /** @var $block \Drupal\block\BlockInterface */
+    $visibility_conditions = $block->getPlugin()->getVisibilityConditions();
+    $visibility = $visibility_conditions->getConfiguration();
     if (isset($visibility['language']['langcodes'][$language->id()])) {
       unset($visibility['language']['langcodes'][$language->id()]);
-      $block->set('visibility', $visibility);
+      $visibility_conditions->setConfiguration($visibility);
       $block->save();
     }
   }
diff --git a/core/modules/block/src/BlockAccessController.php b/core/modules/block/src/BlockAccessController.php
index 3bd9fb3..0089470 100644
--- a/core/modules/block/src/BlockAccessController.php
+++ b/core/modules/block/src/BlockAccessController.php
@@ -8,53 +8,19 @@
 namespace Drupal\block;
 
 use Drupal\Core\Entity\EntityAccessController;
-use Drupal\Core\Entity\EntityControllerInterface;
 use Drupal\Core\Entity\EntityInterface;
-use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Session\AccountInterface;
-use Drupal\Core\Path\AliasManagerInterface;
-use Drupal\Component\Utility\Unicode;
-use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Provides a Block access controller.
  */
-class BlockAccessController extends EntityAccessController implements EntityControllerInterface {
-
-  /**
-   * The node grant storage.
-   *
-   * @var \Drupal\Core\Path\AliasManagerInterface
-   */
-  protected $aliasManager;
-
-  /**
-   * Constructs a BlockAccessController object.
-   *
-   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
-   *   The entity type definition.
-   * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager
-   *   The alias manager.
-   */
-  public function __construct(EntityTypeInterface $entity_type, AliasManagerInterface $alias_manager) {
-    parent::__construct($entity_type);
-    $this->aliasManager = $alias_manager;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
-    return new static(
-      $entity_type,
-      $container->get('path.alias_manager')
-    );
-  }
+class BlockAccessController extends EntityAccessController {
 
   /**
    * {@inheritdoc}
    */
   protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
+    /** @var $entity \Drupal\block\BlockInterface */
     if ($operation != 'view') {
       return parent::checkAccess($entity, $operation, $langcode, $account);
     }
@@ -64,65 +30,8 @@ protected function checkAccess(EntityInterface $entity, $operation, $langcode, A
       return FALSE;
     }
 
-    // User role access handling.
-    // If a block has no roles associated, it is displayed for every role.
-    // For blocks with roles associated, if none of the user's roles matches
-    // the settings from this block, access is denied.
-    $visibility = $entity->get('visibility');
-    if (!empty($visibility['role']['roles']) && !array_intersect(array_filter($visibility['role']['roles']), $account->getRoles())) {
-      // No match.
-      return FALSE;
-    }
-
-    // Page path handling.
-    // Limited visibility blocks must list at least one page.
-    if (!empty($visibility['path']['visibility']) && $visibility['path']['visibility'] == BLOCK_VISIBILITY_LISTED && empty($visibility['path']['pages'])) {
-      return FALSE;
-    }
-
-    // Match path if necessary.
-    if (!empty($visibility['path']['pages'])) {
-      // Assume there are no matches until one is found.
-      $page_match = FALSE;
-
-      // Convert path to lowercase. This allows comparison of the same path
-      // with different case. Ex: /Page, /page, /PAGE.
-      $pages = drupal_strtolower($visibility['path']['pages']);
-      if ($visibility['path']['visibility'] < BLOCK_VISIBILITY_PHP) {
-        // Compare the lowercase path alias (if any) and internal path.
-        $path = current_path();
-        $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path));
-        $page_match = drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages));
-        // When $block->visibility has a value of 0
-        // (BLOCK_VISIBILITY_NOTLISTED), the block is displayed on all pages
-        // except those listed in $block->pages. When set to 1
-        // (BLOCK_VISIBILITY_LISTED), it is displayed only on those pages
-        // listed in $block->pages.
-        $page_match = !($visibility['path']['visibility'] xor $page_match);
-      }
-
-      // If there are page visibility restrictions and this page does not
-      // match, deny access.
-      if (!$page_match) {
-        return FALSE;
-      }
-    }
-
-    // Language visibility settings.
-    if (!empty($visibility['language']['langcodes']) && array_filter($visibility['language']['langcodes'])) {
-      if (empty($visibility['language']['langcodes'][\Drupal::languageManager()->getCurrentLanguage($visibility['language']['language_type'])->id])) {
-        return FALSE;
-      }
-    }
-
-    // If the plugin denies access, then deny access. Apply plugin access checks
-    // last, because it's almost certainly cheaper to first apply Block's own
-    // visibility checks.
-    if (!$entity->getPlugin()->access($account)) {
-      return FALSE;
-    }
-
-    return TRUE;
+    // Delegate to the plugin.
+    return $entity->getPlugin()->access($account);
   }
 
 }
diff --git a/core/modules/block/src/BlockBase.php b/core/modules/block/src/BlockBase.php
index 56b1662..d4b5ee1 100644
--- a/core/modules/block/src/BlockBase.php
+++ b/core/modules/block/src/BlockBase.php
@@ -7,6 +7,9 @@
 
 namespace Drupal\block;
 
+use Drupal\Core\Condition\ConditionAccessResolverTrait;
+use Drupal\Core\Condition\ConditionPluginBag;
+use Drupal\Core\Plugin\Context\Context;
 use Drupal\Core\Plugin\ContextAwarePluginBase;
 use Drupal\block\BlockInterface;
 use Drupal\Component\Utility\Unicode;
@@ -15,6 +18,8 @@
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Cache\CacheableInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\user\Entity\User;
+use Symfony\Cmf\Component\Routing\RouteObjectInterface;
 
 /**
  * Defines a base block implementation that most blocks plugins will extend.
@@ -27,6 +32,22 @@
  */
 abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginInterface {
 
+  use ConditionAccessResolverTrait;
+
+  /**
+   * The condition plugin bag.
+   *
+   * @var \Drupal\Core\Condition\ConditionPluginBag
+   */
+  protected $conditionBag;
+
+  /**
+   * The condition plugin manager.
+   *
+   * @var \Drupal\Core\Executable\ExecutableManagerInterface
+   */
+  protected $conditionPluginManager;
+
   /**
    * {@inheritdoc}
    */
@@ -54,7 +75,9 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    * {@inheritdoc}
    */
   public function getConfiguration() {
-    return $this->configuration;
+    return array(
+      'visibility' => $this->getVisibilityConditions()->getConfiguration(),
+    ) + $this->configuration;
   }
 
   /**
@@ -75,6 +98,20 @@ public function setConfiguration(array $configuration) {
    *   An associative array with the default configuration.
    */
   protected function baseConfigurationDefaults() {
+    // @todo Allow list of conditions to be configured.
+    $visibility = array();
+    if (\Drupal::moduleHandler()->moduleExists('system')) {
+      $visibility['request_path'] = array('id' => 'request_path');
+    }
+    if (\Drupal::moduleHandler()->moduleExists('user')) {
+      $visibility['user_role'] = array('id' => 'user_role');
+    }
+    if (\Drupal::moduleHandler()->moduleExists('node')) {
+      $visibility['node_type'] = array('id' => 'node_type');
+    }
+    if (\Drupal::moduleHandler()->moduleExists('language')) {
+      $visibility['language'] = array('id' => 'language');
+    }
     return array(
       'id' => $this->getPluginId(),
       'label' => '',
@@ -84,6 +121,7 @@ protected function baseConfigurationDefaults() {
         'max_age' => 0,
         'contexts' => array(),
       ),
+      'visibility' => $visibility,
     );
   }
 
@@ -112,6 +150,63 @@ public function calculateDependencies() {
    * {@inheritdoc}
    */
   public function access(AccountInterface $account) {
+    if ($this->resolveConditions($this->getVisibilityConditions(), 'and', $this->getConditionContexts()) === FALSE) {
+      return FALSE;
+    }
+    return $this->blockAccess($account);
+  }
+
+  /**
+   * Gets the values for all defined contexts.
+   *
+   * @return \Drupal\Component\Plugin\Context\ContextInterface[]
+   *   An array of set contexts, keyed by context name.
+   */
+  protected function getConditionContexts() {
+    // @todo Move these hardcoded contexts into an event flow.
+    $context = new Context(array(
+      'type' => 'entity:user',
+      'label' => $this->t('Current user'),
+    ));
+    $context->setContextValue(User::load(\Drupal::currentUser()->id()));
+    $contexts['user'] = $context;
+
+    $language = \Drupal::languageManager()->getCurrentLanguage();
+    $context = new Context(array(
+      'type' => 'language',
+      'label' => $this->t('Current language'),
+    ));
+    $context->setContextValue($language);
+    $contexts['language'] = $context;
+
+    // @todo Use RouteMatch after https://drupal.org/node/2238217.
+    $request = \Drupal::request();
+    if ($request->attributes->has(RouteObjectInterface::ROUTE_OBJECT) && $route_contexts = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)->getOption('parameters')) {
+      foreach ($route_contexts as $route_context_name => $route_context) {
+        if ($route_context_name == 'node') {
+          $context = new Context($route_context);
+          if ($request->attributes->has($route_context_name)) {
+            $context->setContextValue($request->attributes->get($route_context_name));
+          }
+          $contexts[$route_context_name] = $context;
+        }
+      }
+    }
+    return $contexts;
+  }
+
+  /**
+   * Indicates whether the block should be shown.
+   *
+   * @param \Drupal\Core\Session\AccountInterface $account
+   *   The user session for which to check access.
+   *
+   * @return bool
+   *   TRUE if the block should be shown, or FALSE otherwise.
+   *
+   * @see self::access()
+   */
+  protected function blockAccess(AccountInterface $account) {
     // By default, the block is visible unless user-configured rules indicate
     // that it should be hidden.
     return TRUE;
@@ -197,6 +292,16 @@ public function buildConfigurationForm(array $form, array &$form_state) {
       $form['cache']['contexts']['#description'] .= ' ' . t('This block is <em>always</em> varied by the following contexts: %required-context-list.', array('%required-context-list' => $required_context_list));
     }
 
+    // @todo Use vertical tabs here.
+    $form['visibility'] = array(
+      '#type' => 'fieldgroup',
+      '#title' => $this->t('Visibility'),
+    );
+    foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
+      $form['visibility'][$condition_id] = $condition->buildConfigurationForm(array(), $form_state);
+      $form['visibility'][$condition_id]['#type'] = 'details';
+      $form['visibility'][$condition_id]['#title'] = $condition->getPluginDefinition()['label'];
+    }
     // Add plugin-specific settings for this block type.
     $form += $this->blockForm($form, $form_state);
     return $form;
@@ -221,6 +326,15 @@ public function validateConfigurationForm(array &$form, array &$form_state) {
     // Transform the #type = checkboxes value to a numerically indexed array.
     $form_state['values']['cache']['contexts'] = array_values(array_filter($form_state['values']['cache']['contexts']));
 
+    foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
+      // Allow the condition to validate the form.
+      $condition_values = array(
+        'values' => &$form_state['values']['visibility'][$condition_id],
+      );
+      $condition->validateConfigurationForm($form, $condition_values);
+
+    }
+
     $this->blockValidate($form, $form_state);
   }
 
@@ -244,6 +358,13 @@ public function submitConfigurationForm(array &$form, array &$form_state) {
       $this->configuration['label_display'] = $form_state['values']['label_display'];
       $this->configuration['provider'] = $form_state['values']['provider'];
       $this->configuration['cache'] = $form_state['values']['cache'];
+      foreach ($this->getVisibilityConditions() as $condition_id => $condition) {
+        // Allow the condition to submit the form.
+        $condition_values = array(
+          'values' => &$form_state['values']['visibility'][$condition_id],
+        );
+        $condition->submitConfigurationForm($form, $condition_values);
+      }
       $this->blockSubmit($form, $form_state);
     }
   }
@@ -332,4 +453,40 @@ public function isCacheable() {
     return $max_age === Cache::PERMANENT || $max_age > 0;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getVisibilityConditions() {
+    if (!isset($this->conditionBag)) {
+      $this->conditionBag = new ConditionPluginBag($this->conditionPluginManager(), $this->configuration['visibility']);
+    }
+    return $this->conditionBag;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getVisibilityCondition($instance_id) {
+    return $this->getVisibilityConditions()->get($instance_id);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setVisibilityConfig($instance_id, array $configuration) {
+    $this->getVisibilityConditions()->setInstanceConfiguration($instance_id, $configuration);
+    return $this;
+  }
+
+  /**
+   * Gets the condition plugin manager.
+   * @return \Drupal\Core\Executable\ExecutableManagerInterface
+   *   The condition plugin manager.
+   */
+  protected function conditionPluginManager() {
+    if (!isset($this->conditionPluginManager)) {
+      $this->conditionPluginManager = \Drupal::service('plugin.manager.condition');
+    }
+    return $this->conditionPluginManager;
+  }
 }
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index 866f1b8..af8641c 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -10,9 +10,6 @@
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Entity\EntityForm;
 use Drupal\Core\Entity\EntityManagerInterface;
-use Drupal\Core\Language\LanguageInterface;
-use Drupal\Core\Language\LanguageManagerInterface;
-use Drupal\language\ConfigurableLanguageManagerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -35,23 +32,13 @@ class BlockForm extends EntityForm {
   protected $storage;
 
   /**
-   * The language manager.
-   *
-   * @var \Drupal\Core\Language\LanguageManagerInterface
-   */
-  protected $languageManager;
-
-  /**
    * Constructs a BlockForm object.
    *
    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
    *   The entity manager.
-   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
-   *   The language manager.
    */
-  public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
+  public function __construct(EntityManagerInterface $entity_manager) {
     $this->storage = $entity_manager->getStorage('block');
-    $this->languageManager = $language_manager;
   }
 
   /**
@@ -59,8 +46,7 @@ public function __construct(EntityManagerInterface $entity_manager, LanguageMana
    */
   public static function create(ContainerInterface $container) {
     return new static(
-      $container->get('entity.manager'),
-      $container->get('language_manager')
+      $container->get('entity.manager')
     );
   }
 
@@ -94,122 +80,6 @@ public function form(array $form, array &$form_state) {
       '#disabled' => !$entity->isNew(),
     );
 
-    // Visibility settings.
-    $form['visibility'] = array(
-      '#type' => 'vertical_tabs',
-      '#title' => $this->t('Visibility settings'),
-      '#attached' => array(
-        'library' => array(
-          'block/drupal.block',
-        ),
-      ),
-      '#tree' => TRUE,
-      '#weight' => 10,
-      '#parents' => array('visibility'),
-    );
-
-    // Per-path visibility.
-    $form['visibility']['path'] = array(
-      '#type' => 'details',
-      '#title' => $this->t('Pages'),
-      '#group' => 'visibility',
-      '#weight' => 0,
-    );
-
-    // @todo remove this access check and inject it in some other way. In fact
-    //   this entire visibility settings section probably needs a separate user
-    //   interface in the near future.
-    $visibility = $entity->get('visibility');
-    $access = $this->currentUser()->hasPermission('use PHP for settings');
-    if (!empty($visibility['path']['visibility']) && $visibility['path']['visibility'] == BLOCK_VISIBILITY_PHP && !$access) {
-      $form['visibility']['path']['visibility'] = array(
-        '#type' => 'value',
-        '#value' => BLOCK_VISIBILITY_PHP,
-      );
-      $form['visibility']['path']['pages'] = array(
-        '#type' => 'value',
-        '#value' => !empty($visibility['path']['pages']) ? $visibility['path']['pages'] : '',
-      );
-    }
-    else {
-      $options = array(
-        BLOCK_VISIBILITY_NOTLISTED => $this->t('All pages except those listed'),
-        BLOCK_VISIBILITY_LISTED => $this->t('Only the listed pages'),
-      );
-      $description = $this->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %user for the current user's page and %user-wildcard for every user page. %front is the front page.", array('%user' => 'user', '%user-wildcard' => 'user/*', '%front' => '<front>'));
-
-      $form['visibility']['path']['visibility'] = array(
-        '#type' => 'radios',
-        '#title' => $this->t('Show block on specific pages'),
-        '#options' => $options,
-        '#default_value' => !empty($visibility['path']['visibility']) ? $visibility['path']['visibility'] : BLOCK_VISIBILITY_NOTLISTED,
-      );
-      $form['visibility']['path']['pages'] = array(
-        '#type' => 'textarea',
-        '#title' => '<span class="visually-hidden">' . $this->t('Pages') . '</span>',
-        '#default_value' => !empty($visibility['path']['pages']) ? $visibility['path']['pages'] : '',
-        '#description' => $description,
-      );
-    }
-
-    // Configure the block visibility per language.
-    if ($this->languageManager->isMultilingual() && $this->languageManager instanceof ConfigurableLanguageManagerInterface) {
-      $language_types = $this->languageManager->getLanguageTypes();
-
-      // Fetch languages.
-      $languages = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
-      $langcodes_options = array();
-      foreach ($languages as $language) {
-        // @todo $language->name is not wrapped with t(), it should be replaced
-        //   by CMI translation implementation.
-        $langcodes_options[$language->id] = $language->name;
-      }
-      $form['visibility']['language'] = array(
-        '#type' => 'details',
-        '#title' => $this->t('Languages'),
-        '#group' => 'visibility',
-        '#weight' => 5,
-      );
-      // If there are multiple configurable language types, let the user pick
-      // which one should be applied to this visibility setting. This way users
-      // can limit blocks by interface language or content language for example.
-      $info = $this->languageManager->getDefinedLanguageTypesInfo();
-      $language_type_options = array();
-      foreach ($language_types as $type_key) {
-        $language_type_options[$type_key] = $info[$type_key]['name'];
-      }
-      $form['visibility']['language']['language_type'] = array(
-        '#type' => 'radios',
-        '#title' => $this->t('Language type'),
-        '#options' => $language_type_options,
-        '#default_value' => !empty($visibility['language']['language_type']) ? $visibility['language']['language_type'] : reset($language_types),
-        '#access' => count($language_type_options) > 1,
-      );
-      $form['visibility']['language']['langcodes'] = array(
-        '#type' => 'checkboxes',
-        '#title' => $this->t('Show this block only for specific languages'),
-        '#default_value' => !empty($visibility['language']['langcodes']) ? $visibility['language']['langcodes'] : array(),
-        '#options' => $langcodes_options,
-        '#description' => $this->t('Show this block only for the selected language(s). If you select no languages, the block will be visible in all languages.'),
-      );
-    }
-
-    // Per-role visibility.
-    $role_options = array_map('check_plain', user_role_names());
-    $form['visibility']['role'] = array(
-      '#type' => 'details',
-      '#title' => $this->t('Roles'),
-      '#group' => 'visibility',
-      '#weight' => 10,
-    );
-    $form['visibility']['role']['roles'] = array(
-      '#type' => 'checkboxes',
-      '#title' => $this->t('Show block for specific roles'),
-      '#default_value' => !empty($visibility['role']['roles']) ? $visibility['role']['roles'] : array(),
-      '#options' => $role_options,
-      '#description' => $this->t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
-    );
-
     // Theme settings.
     if ($entity->get('theme')) {
       $form['theme'] = array(
@@ -276,8 +146,6 @@ protected function actions(array $form, array &$form_state) {
   public function validate(array $form, array &$form_state) {
     parent::validate($form, $form_state);
 
-    // Remove empty lines from the role visibility list.
-    $form_state['values']['visibility']['role']['roles'] = array_filter($form_state['values']['visibility']['role']['roles']);
     // The Block Entity form puts all block plugin form elements in the
     // settings form element, so just pass that to the block for validation.
     $settings = array(
@@ -324,21 +192,6 @@ public function submit(array $form, array &$form_state) {
   }
 
   /**
-   * {@inheritdoc}
-   */
-  public function buildEntity(array $form, array &$form_state) {
-    $entity = parent::buildEntity($form, $form_state);
-
-    // visibility__active_tab is Form API state and not configuration.
-    // @todo Fix vertical tabs.
-    $visibility = $entity->get('visibility');
-    unset($visibility['visibility__active_tab']);
-    $entity->set('visibility', $visibility);
-
-    return $entity;
-  }
-
-  /**
    * Generates a unique machine name for a block.
    *
    * @param \Drupal\block\BlockInterface $block
diff --git a/core/modules/block/src/BlockManager.php b/core/modules/block/src/BlockManager.php
index 4a1651b..1db10a6 100644
--- a/core/modules/block/src/BlockManager.php
+++ b/core/modules/block/src/BlockManager.php
@@ -10,6 +10,7 @@
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Extension\ModuleHandlerInterface;
 use Drupal\Core\Language\LanguageManager;
+use Drupal\Core\Plugin\Context\ContextAwarePluginManagerTrait;
 use Drupal\Core\Plugin\DefaultPluginManager;
 use Drupal\Core\StringTranslation\TranslationInterface;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -24,6 +25,7 @@
 class BlockManager extends DefaultPluginManager implements BlockManagerInterface {
 
   use StringTranslationTrait;
+  use ContextAwarePluginManagerTrait;
 
   /**
    * An array of all available modules and their data.
@@ -106,7 +108,7 @@ public function getCategories() {
    */
   public function getSortedDefinitions() {
     // Sort the plugins first by category, then by label.
-    $definitions = $this->getDefinitions();
+    $definitions = $this->getDefinitionsForContexts();
     uasort($definitions, function ($a, $b) {
       if ($a['category'] != $b['category']) {
         return strnatcasecmp($a['category'], $b['category']);
diff --git a/core/modules/block/src/BlockManagerInterface.php b/core/modules/block/src/BlockManagerInterface.php
index 4973f16..6656004 100644
--- a/core/modules/block/src/BlockManagerInterface.php
+++ b/core/modules/block/src/BlockManagerInterface.php
@@ -7,12 +7,12 @@
 
 namespace Drupal\block;
 
-use Drupal\Component\Plugin\PluginManagerInterface;
+use Drupal\Core\Plugin\Context\ContextAwarePluginManagerInterface;
 
 /**
  * Provides an interface for the discovery and instantiation of block plugins.
  */
-interface BlockManagerInterface extends PluginManagerInterface {
+interface BlockManagerInterface extends ContextAwarePluginManagerInterface {
 
   /**
    * Gets the names of all block categories.
diff --git a/core/modules/block/src/BlockPluginInterface.php b/core/modules/block/src/BlockPluginInterface.php
index f45ecc5..58ecc8c 100644
--- a/core/modules/block/src/BlockPluginInterface.php
+++ b/core/modules/block/src/BlockPluginInterface.php
@@ -140,4 +140,35 @@ public function blockSubmit($form, &$form_state);
    */
   public function getMachineNameSuggestion();
 
+  /**
+   * Gets conditions for this block.
+   *
+   * @return \Drupal\Core\Condition\ConditionInterface[]|\Drupal\Core\Condition\ConditionPluginBag
+   *   An array of configured condition plugins.
+   */
+  public function getVisibilityConditions();
+
+  /**
+   * Gets a visibility condition plugin instance.
+   *
+   * @param string $instance_id
+   *   The condition plugin instance ID.
+   *
+   * @return \Drupal\Core\Condition\ConditionInterface
+   *   A condition plugin.
+   */
+  public function getVisibilityCondition($instance_id);
+
+  /**
+   * Sets the visibility condition configuration.
+   *
+   * @param string $instance_id
+   *   The condition instance ID.
+   * @param array $configuration
+   *   The condition configuration.
+   *
+   * @return $this
+   */
+  public function setVisibilityConfig($instance_id, array $configuration);
+
 }
diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php
index de6c971..d11347a 100644
--- a/core/modules/block/src/Entity/Block.php
+++ b/core/modules/block/src/Entity/Block.php
@@ -87,13 +87,6 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
   protected $pluginBag;
 
   /**
-   * The visibility settings.
-   *
-   * @var array
-   */
-  protected $visibility;
-
-  /**
    * {@inheritdoc}
    */
   public function getPlugin() {
@@ -145,7 +138,6 @@ public function toArray() {
       'weight',
       'plugin',
       'settings',
-      'visibility',
     );
     foreach ($names as $name) {
       $properties[$name] = $this->get($name);
diff --git a/core/modules/block/src/Tests/BlockInterfaceTest.php b/core/modules/block/src/Tests/BlockInterfaceTest.php
index 0b71146..35df3e8 100644
--- a/core/modules/block/src/Tests/BlockInterfaceTest.php
+++ b/core/modules/block/src/Tests/BlockInterfaceTest.php
@@ -44,6 +44,18 @@ public function testBlockInterface() {
       'label' => 'Custom Display Message',
     );
     $expected_configuration = array(
+      'visibility' => array(
+        'request_path' => array(
+          'id' => 'request_path',
+          'pages' => '',
+          'negate' => FALSE,
+        ),
+        'user_role' => array(
+          'id' => 'user_role',
+          'roles' => array(),
+          'negate' => FALSE,
+        ),
+      ),
       'id' => 'test_block_instantiation',
       'label' => 'Custom Display Message',
       'provider' => 'block_test',
@@ -55,6 +67,7 @@ public function testBlockInterface() {
       'display_message' => 'no message set',
     );
     // Initial configuration of the block at construction time.
+    /** @var $display_block \Drupal\block\BlockPluginInterface */
     $display_block = $manager->createInstance('test_block_instantiation', $configuration);
     $this->assertIdentical($display_block->getConfiguration(), $expected_configuration, 'The block was configured correctly.');
 
@@ -124,7 +137,10 @@ public function testBlockInterface() {
     );
     $form_state = array();
     // Ensure there are no form elements that do not belong to the plugin.
-    $this->assertIdentical($display_block->buildConfigurationForm(array(), $form_state), $expected_form, 'Only the expected form elements were present.');
+    $actual_form = $display_block->buildConfigurationForm(array(), $form_state);
+    // Remove the visibility section, as that just tests condition plugins.
+    unset($actual_form['visibility']);
+    $this->assertIdentical($actual_form, $expected_form, 'Only the expected form elements were present.');
 
     $expected_build = array(
       '#children' => 'My custom display message.',
diff --git a/core/modules/block/src/Tests/BlockLanguageTest.php b/core/modules/block/src/Tests/BlockLanguageTest.php
index 246e92c..a3a1837 100644
--- a/core/modules/block/src/Tests/BlockLanguageTest.php
+++ b/core/modules/block/src/Tests/BlockLanguageTest.php
@@ -57,11 +57,11 @@ public function testLanguageBlockVisibility() {
     $default_theme = \Drupal::config('system.theme')->get('default');
     $this->drupalGet('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme);
 
-    $this->assertField('visibility[language][langcodes][en]', 'Language visibility field is visible.');
+    $this->assertField('settings[visibility][language][langcodes][en]', 'Language visibility field is visible.');
 
     // Enable a standard block and set the visibility setting for one language.
     $edit = array(
-      'visibility[language][langcodes][en]' => TRUE,
+      'settings[visibility][language][langcodes][en]' => TRUE,
       'id' => strtolower($this->randomName(8)),
       'region' => 'sidebar_first',
     );
@@ -100,7 +100,7 @@ public function testLanguageBlockVisibilityLanguageDelete() {
     $block = $this->drupalPlaceBlock('system_powered_by_block', $edit);
 
     // Check that we have the language in config after saving the setting.
-    $visibility = $block->get('visibility');
+    $visibility = $block->getPlugin()->getVisibilityConditions()->getConfiguration();
     $language = $visibility['language']['langcodes']['fr'];
     $this->assertTrue('fr' === $language, 'Language is set in the block configuration.');
 
@@ -110,7 +110,7 @@ public function testLanguageBlockVisibilityLanguageDelete() {
     // Check that the language is no longer stored in the configuration after
     // it is deleted.
     $block = entity_load('block', $block->id());
-    $visibility = $block->get('visibility');
+    $visibility = $block->getPlugin()->getVisibilityConditions()->getConfiguration();
     $this->assertTrue(empty($visibility['language']['langcodes']['fr']), 'Language is no longer not set in the block configuration after deleting the block.');
   }
 
diff --git a/core/modules/block/src/Tests/BlockStorageUnitTest.php b/core/modules/block/src/Tests/BlockStorageUnitTest.php
index 65d67f6..60cbf94 100644
--- a/core/modules/block/src/Tests/BlockStorageUnitTest.php
+++ b/core/modules/block/src/Tests/BlockStorageUnitTest.php
@@ -99,6 +99,13 @@ protected function createTests() {
       'region' => '-1',
       'plugin' => 'test_html',
       'settings' => array(
+        'visibility' => array(
+          'request_path' => array(
+            'id' => 'request_path',
+            'pages' => '',
+            'negate' => FALSE,
+          ),
+        ),
         'id' => 'test_html',
         'label' => '',
         'provider' => 'block_test',
@@ -108,7 +115,6 @@ protected function createTests() {
           'contexts' => array(),
         ),
       ),
-      'visibility' => NULL,
     );
     $this->assertIdentical($actual_properties, $expected_properties);
 
diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php
index 882863d..741fab1 100644
--- a/core/modules/block/src/Tests/BlockTest.php
+++ b/core/modules/block/src/Tests/BlockTest.php
@@ -40,8 +40,9 @@ function testBlockVisibility() {
     );
     // Set the block to be hidden on any user path, and to be shown only to
     // authenticated users.
-    $edit['visibility[path][pages]'] = 'user*';
-    $edit['visibility[role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
+    $edit['settings[visibility][request_path][pages]'] = 'user*';
+    $edit['settings[visibility][request_path][negate]'] = TRUE;
+    $edit['settings[visibility][user_role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
     $this->drupalPostForm('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block'));
     $this->assertText('The block configuration has been saved.', 'Block was saved');
 
@@ -65,8 +66,7 @@ function testBlockVisibility() {
   }
 
   /**
-   * Test block visibility when using "pages" restriction but leaving
-   * "pages" textarea empty
+   * Test block visibility when leaving "pages" textarea empty.
    */
   function testBlockVisibilityListedEmpty() {
     $block_name = 'system_powered_by_block';
@@ -78,7 +78,7 @@ function testBlockVisibilityListedEmpty() {
       'id' => strtolower($this->randomName(8)),
       'region' => 'sidebar_first',
       'settings[label]' => $title,
-      'visibility[path][visibility]' => BLOCK_VISIBILITY_LISTED,
+      'settings[visibility][request_path][negate]' => TRUE,
     );
     // Set the block to be hidden on any user path, and to be shown only to
     // authenticated users.
diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php
index d842401..5c2dbfa 100644
--- a/core/modules/block/src/Tests/BlockUiTest.php
+++ b/core/modules/block/src/Tests/BlockUiTest.php
@@ -158,6 +158,24 @@ public function testCandidateBlockList() {
   }
 
   /**
+   * Tests the behavior of context-aware blocks.
+   */
+  public function testContextAwareBlocks() {
+    $arguments = array(
+      ':ul_class' => 'block-list',
+      ':li_class' => 'test-context-aware',
+      ':href' => 'admin/structure/block/add/test_context_aware/stark',
+      ':text' => 'Test context-aware block',
+    );
+
+    $this->drupalGet('admin/structure/block');
+    $elements = $this->xpath('//details[@id="edit-category-block-test"]//ul[contains(@class, :ul_class)]/li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
+    $this->assertTrue(empty($elements), 'The context-aware test block does not appear.');
+    $definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware');
+    $this->assertTrue(!empty($definition), 'The context-aware test block exists.');
+  }
+
+  /**
    * Tests that the BlockForm populates machine name correctly.
    */
   public function testMachineNameSuggestion() {
diff --git a/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml b/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
index 232c64a..ea4a909 100644
--- a/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
+++ b/core/modules/block/tests/modules/block_test/config/install/block.block.test_block.yml
@@ -6,17 +6,13 @@ langcode: en
 region: '-1'
 plugin: test_html
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
   label: 'Test HTML block'
   provider: block_test
   label_display: 'hidden'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types: {  }
 dependencies:
   module:
     - block_test
diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php
index 85856a3..9a4db70 100644
--- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php
+++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestBlockInstantiation.php
@@ -32,7 +32,7 @@ public function defaultConfiguration() {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return $account->hasPermission('access content');
   }
 
diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
new file mode 100644
index 0000000..ae2550b
--- /dev/null
+++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\block_test\Plugin\Block\TestContextAwareBlock.
+ */
+
+namespace Drupal\block_test\Plugin\Block;
+
+use Drupal\block\BlockBase;
+
+/**
+ * Provides a context-aware block.
+ *
+ * @Block(
+ *   id = "test_context_aware",
+ *   admin_label = @Translation("Test context-aware block"),
+ *   context = {
+ *     "user" = {
+ *       "type" = "entity:user"
+ *     }
+ *   }
+ * )
+ */
+class TestContextAwareBlock extends BlockBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function build() {
+    /** @var $user \Drupal\user\UserInterface */
+    $user = $this->getContextValue('user');
+    return array(
+      '#markup' => $user->getUsername(),
+    );
+  }
+
+}
diff --git a/core/modules/block/tests/src/BlockBaseTest.php b/core/modules/block/tests/src/BlockBaseTest.php
index 913130b..6fddb58 100644
--- a/core/modules/block/tests/src/BlockBaseTest.php
+++ b/core/modules/block/tests/src/BlockBaseTest.php
@@ -9,7 +9,7 @@
 
 use Drupal\block_test\Plugin\Block\TestBlockInstantiation;
 use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\Core\Transliteration\PHPTransliteration;
+use Drupal\Core\Executable\ExecutableManagerInterface;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -33,24 +33,92 @@ public static function getInfo() {
    * @see \Drupal\block\BlockBase::getMachineNameSuggestion().
    */
   public function testGetMachineNameSuggestion() {
+    $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
     $transliteraton = $this->getMockBuilder('Drupal\Core\Transliteration\PHPTransliteration')
       // @todo Inject the module handler into PHPTransliteration.
       ->setMethods(array('readLanguageOverrides'))
       ->getMock();
 
     $container = new ContainerBuilder();
+    $container->set('module_handler', $module_handler);
     $container->set('transliteration', $transliteraton);
     \Drupal::setContainer($container);
 
     $config = array();
-    $definition = array('admin_label' => 'Admin label', 'provider' => 'block_test');
+    $definition = array(
+      'admin_label' => 'Admin label',
+      'provider' => 'block_test',
+    );
     $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
     $this->assertEquals('adminlabel', $block_base->getMachineNameSuggestion());
 
     // Test with more unicodes.
-    $definition = array('admin_label' =>'über åwesome', 'provider' => 'block_test');
+    $definition = array(
+      'admin_label' => 'über åwesome',
+      'provider' => 'block_test',
+    );
     $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
     $this->assertEquals('uberawesome', $block_base->getMachineNameSuggestion());
   }
 
+  /**
+   * Tests initialising the condition plugins initialisation.
+   */
+  public function testCondtionsBagInitialisation() {
+    $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
+    $module_handler->expects($this->exactly(4))
+      ->method('moduleExists')
+      ->will($this->returnValueMap(array(
+        array('system', TRUE),
+        array('user', TRUE),
+        array('node', TRUE),
+        array('language', TRUE),
+      )));
+    $container = new ContainerBuilder();
+    $container->set('module_handler', $module_handler);
+    \Drupal::setContainer($container);
+    $config = array();
+    $definition = array(
+      'admin_label' => 'Admin label',
+      'provider' => 'block_test',
+    );
+
+    $plugin_manager = $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface');
+
+    $block_base = new FakeBlock($plugin_manager, $config, 'test_block_instantiation', $definition);
+    $conditions_bag = $block_base->getVisibilityConditions();
+
+    $this->assertEquals(4, $conditions_bag->count(), "There are 4 condition plugins");
+
+    $instance_id = $this->randomName();
+    $pages = 'node/1';
+    $condition_config = array('id' => 'request_path', 'pages' => $pages);
+    $block_base->setVisibilityConfig($instance_id, $condition_config);
+
+    $plugin_manager->expects($this->once())->method('createInstance')
+      ->withAnyParameters()->will($this->returnValue('test'));
+
+    $condition = $block_base->getVisibilityCondition($instance_id);
+
+    $this->assertEquals('test', $condition, "The correct condition is returned.");
+  }
+
+}
+
+/**
+ * A fake Block for testing condition plugin config.
+ */
+class FakeBlock extends TestBlockInstantiation {
+
+  protected $mockPluginManager;
+
+  public function __construct(ExecutableManagerInterface $plugin_manager, array $configuration, $plugin_id, $plugin_definition) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+    $this->mockPluginManager = $plugin_manager;
+  }
+
+  protected function conditionPluginManager() {
+    return $this->mockPluginManager;
+  }
+
 }
diff --git a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php
index d7dfc31..6a5b492 100644
--- a/core/modules/forum/src/Plugin/Block/ForumBlockBase.php
+++ b/core/modules/forum/src/Plugin/Block/ForumBlockBase.php
@@ -56,7 +56,7 @@ public function defaultConfiguration() {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return $account->hasPermission('access content');
   }
 
diff --git a/core/modules/language/config/schema/language.schema.yml b/core/modules/language/config/schema/language.schema.yml
index a10dc3d..584a715 100644
--- a/core/modules/language/config/schema/language.schema.yml
+++ b/core/modules/language/config/schema/language.schema.yml
@@ -123,3 +123,11 @@ language.settings:
                         language_show:
                           type: boolean
                           label: 'Show language selector on create and edit pages'
+
+condition.plugin.language:
+  type: condition.plugin
+  mapping:
+    langcodes:
+      type: sequence
+      sequence:
+        - type: string
diff --git a/core/modules/language/src/Plugin/Block/LanguageBlock.php b/core/modules/language/src/Plugin/Block/LanguageBlock.php
index 4a6c7bc..42d5bf3 100644
--- a/core/modules/language/src/Plugin/Block/LanguageBlock.php
+++ b/core/modules/language/src/Plugin/Block/LanguageBlock.php
@@ -66,7 +66,7 @@ public static function create(ContainerInterface $container, array $configuratio
   /**
    * {@inheritdoc}
    */
-  function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return $this->languageManager->isMultilingual();
   }
 
diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php
index 3f12a06..ff64464 100644
--- a/core/modules/language/src/Plugin/Condition/Language.php
+++ b/core/modules/language/src/Plugin/Condition/Language.php
@@ -35,7 +35,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
       $languages = language_list(Lang::STATE_ALL);
       $langcodes_options = array();
       foreach ($languages as $language) {
-        $langcodes_options[$language->id] = $language->label();
+        $langcodes_options[$language->id] = $language->getName();
       }
       $form['langcodes'] = array(
         '#type' => 'checkboxes',
@@ -96,12 +96,13 @@ public function summary() {
    * {@inheritdoc}
    */
   public function evaluate() {
+    if (empty($this->configuration['langcodes']) && !$this->configuration['negate']) {
+      return TRUE;
+    }
+
     $language = $this->getContextValue('language');
     // Language visibility settings.
-    if (!empty($this->configuration['langcodes'])) {
-      return !empty($this->configuration['langcodes'][$language->id]);
-    }
-    return TRUE;
+    return !empty($this->configuration['langcodes'][$language->id]);
   }
 
 }
diff --git a/core/modules/node/config/schema/node.schema.yml b/core/modules/node/config/schema/node.schema.yml
index 4e8a55c..8ebe374 100644
--- a/core/modules/node/config/schema/node.schema.yml
+++ b/core/modules/node/config/schema/node.schema.yml
@@ -137,3 +137,11 @@ block.settings.node_syndicate_block:
     block_count:
       type: integer
       label: 'Block count'
+
+condition.plugin.node_type:
+  type: condition.plugin
+  mapping:
+    bundles:
+      type: sequence
+      sequence:
+        - type: string
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 6174a13..a311051 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -937,71 +937,6 @@ function node_get_recent($number = 10) {
 }
 
 /**
- * Implements hook_form_FORM_ID_alter() for block_form().
- *
- * Adds node-type specific visibility options to block configuration form.
- */
-function node_form_block_form_alter(&$form, &$form_state) {
-  $block = $form_state['controller']->getEntity();
-  $visibility = $block->get('visibility');
-  $form['visibility']['node_type'] = array(
-    '#type' => 'details',
-    '#title' => t('Content types'),
-    '#group' => 'visibility',
-    '#weight' => 5,
-  );
-  $form['visibility']['node_type']['types'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Show block for specific content types'),
-    '#default_value' => !empty($visibility['node_type']['types']) ? $visibility['node_type']['types'] : array(),
-    '#options' => node_type_get_names(),
-    '#description' => t('Show this block only on pages that display content of the given type(s). If you select no types, there will be no type-specific limitation.'),
-  );
-}
-
-/**
- * Implements hook_block_access().
- *
- * Checks the content type specific visibility settings and removes the block
- * if the visibility conditions are not met.
- */
-function node_block_access(Block $block, $operation, AccountInterface $account, $langcode) {
-  // Only affect access when viewing the block.
-  if ($operation != 'view') {
-    return;
-  }
-  $visibility = $block->get('visibility');
-  if (!empty($visibility)) {
-    if (!empty($visibility['node_type']['types'])) {
-      $allowed_types = array_filter($visibility['node_type']['types']);
-    }
-    if (empty($allowed_types)) {
-      // There are no node types selected in visibility settings so there is
-      // nothing to do.
-      // @see node_form_block_form_alter()
-      return;
-    }
-
-    // For blocks with node types associated, if the node type does not match
-    // the settings from this block, deny access to it.
-    $request = \Drupal::request();
-    if ($node = $request->attributes->get('node')) {
-      // Page has node.
-      return in_array($node->bundle(), $allowed_types);
-    }
-    // This is a node creation page.
-    // $request->attributes->has('node_type') would also match administration
-    // configuration pages, which the previous URI path options did not.
-    if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'node.add') {
-      $node_type = $request->attributes->get('node_type');
-      return in_array($node_type->id(), $allowed_types);
-    }
-
-    return FALSE;
-  }
-}
-
-/**
  * Page callback: Generates and prints an RSS feed.
  *
  * Generates an RSS feed from an array of node IDs, and prints it with an HTTP
diff --git a/core/modules/node/src/Plugin/Block/SyndicateBlock.php b/core/modules/node/src/Plugin/Block/SyndicateBlock.php
index efc1bdf..ace314a 100644
--- a/core/modules/node/src/Plugin/Block/SyndicateBlock.php
+++ b/core/modules/node/src/Plugin/Block/SyndicateBlock.php
@@ -33,7 +33,7 @@ public function defaultConfiguration() {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return $account->hasPermission('access content');
   }
 
diff --git a/core/modules/node/src/Plugin/Condition/NodeType.php b/core/modules/node/src/Plugin/Condition/NodeType.php
index 74cdf5d..95da12b 100644
--- a/core/modules/node/src/Plugin/Condition/NodeType.php
+++ b/core/modules/node/src/Plugin/Condition/NodeType.php
@@ -37,7 +37,6 @@ public function buildConfigurationForm(array $form, array &$form_state) {
       '#title' => t('Node types'),
       '#type' => 'checkboxes',
       '#options' => $options,
-      '#required' => TRUE,
       '#default_value' => isset($this->configuration['bundles']) ? $this->configuration['bundles'] : array(),
     );
     return $form;
@@ -80,6 +79,9 @@ public function summary() {
    * {@inheritdoc}
    */
   public function evaluate() {
+    if (empty($this->configuration['bundles']) && !$this->configuration['negate']) {
+      return TRUE;
+    }
     $node = $this->getContextValue('node');
     return !empty($this->configuration['bundles'][$node->getType()]);
   }
diff --git a/core/modules/search/src/Plugin/Block/SearchBlock.php b/core/modules/search/src/Plugin/Block/SearchBlock.php
index c2e3e51..64b3096 100644
--- a/core/modules/search/src/Plugin/Block/SearchBlock.php
+++ b/core/modules/search/src/Plugin/Block/SearchBlock.php
@@ -26,7 +26,7 @@ class SearchBlock extends BlockBase {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return $account->hasPermission('search content');
   }
 
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index bd3f8fd..7fb269d 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -427,11 +427,14 @@ protected function drupalPlaceBlock($plugin_id, array $settings = array()) {
         'max_age' => 0,
       ),
     );
-    foreach (array('region', 'id', 'theme', 'plugin', 'visibility', 'weight') as $key) {
+    foreach (array('region', 'id', 'theme', 'plugin', 'weight') as $key) {
       $values[$key] = $settings[$key];
       // Remove extra values that do not belong in the settings array.
       unset($settings[$key]);
     }
+    foreach ($settings['visibility'] as $id => $visibility) {
+      $settings['visibility'][$id]['id'] = $id;
+    }
     $values['settings'] = $settings;
     $block = entity_create('block', $values);
     $block->save();
diff --git a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
index 1a19761..3bdacac 100644
--- a/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
+++ b/core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php
@@ -55,7 +55,7 @@ public function defaultConfiguration() {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     if ($account->hasPermission('access content')) {
       $daytop = $this->configuration['top_day_num'];
       if (!$daytop || !($result = statistics_title_list('daycount', $daytop)) || !($this->day_list = node_title_list($result, t("Today's:")))) {
diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml
index 8c08c10..c3e3bc3 100644
--- a/core/modules/system/config/schema/system.schema.yml
+++ b/core/modules/system/config/schema/system.schema.yml
@@ -367,3 +367,9 @@ block.settings.system_branding_block:
     use_site_slogan:
       type: boolean
       label: 'Use site slogan'
+
+condition.plugin.request_path:
+  type: condition.plugin
+  mapping:
+    pages:
+      type: string
diff --git a/core/modules/system/src/Plugin/Block/SystemHelpBlock.php b/core/modules/system/src/Plugin/Block/SystemHelpBlock.php
index d15cfc6..e99787c 100644
--- a/core/modules/system/src/Plugin/Block/SystemHelpBlock.php
+++ b/core/modules/system/src/Plugin/Block/SystemHelpBlock.php
@@ -78,7 +78,7 @@ public static function create(ContainerInterface $container, array $configuratio
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     $this->help = $this->getActiveHelp($this->request);
     return (bool) $this->help;
   }
diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php
index 7923554..2043b77 100644
--- a/core/modules/system/src/Plugin/Condition/RequestPath.php
+++ b/core/modules/system/src/Plugin/Condition/RequestPath.php
@@ -87,7 +87,7 @@ public static function create(ContainerInterface $container, array $configuratio
    * {@inheritdoc}
    */
   public function defaultConfiguration() {
-    return array('pages' => '');
+    return array('pages' => '') + parent::defaultConfiguration();
   }
 
   /**
@@ -134,6 +134,9 @@ public function evaluate() {
     // Convert path to lowercase. This allows comparison of the same path
     // with different case. Ex: /Page, /page, /PAGE.
     $pages = Unicode::strtolower($this->configuration['pages']);
+    if (!$pages) {
+      return TRUE;
+    }
 
     $request = $this->requestStack->getCurrentRequest();
     // Compare the lowercase path alias (if any) and internal path.
@@ -142,4 +145,5 @@ public function evaluate() {
 
     return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages));
   }
+
 }
diff --git a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php
index f310b24..a22dfb2 100644
--- a/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php
+++ b/core/modules/system/src/Tests/Cache/PageCacheTagsIntegrationTest.php
@@ -67,8 +67,7 @@ function testPageCacheTags() {
     // Place a block, but only make it visible on full node page 2.
     $block = $this->drupalPlaceBlock('views_block:comments_recent-block_1', array(
       'visibility' => array(
-        'path' => array(
-          'visibility' => BLOCK_VISIBILITY_LISTED,
+        'request_path' => array(
           'pages' => 'node/' . $node_2->id(),
         ),
       )
diff --git a/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php b/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php
index 9703f4c..21b79b3 100644
--- a/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php
+++ b/core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php
@@ -66,7 +66,7 @@ public static function create(ContainerInterface $container, array $configuratio
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return TRUE;
   }
 
diff --git a/core/modules/user/config/schema/user.schema.yml b/core/modules/user/config/schema/user.schema.yml
index 70d8581..44762ed 100644
--- a/core/modules/user/config/schema/user.schema.yml
+++ b/core/modules/user/config/schema/user.schema.yml
@@ -162,3 +162,11 @@ search.plugin.user_search:
   label: 'User search'
   sequence:
     - type: undefined
+
+condition.plugin.user_role:
+  type: condition.plugin
+  mapping:
+    roles:
+      type: sequence
+      sequence:
+        - type: string
diff --git a/core/modules/user/src/Plugin/Block/UserLoginBlock.php b/core/modules/user/src/Plugin/Block/UserLoginBlock.php
index 01e1ebd..2cd54f4 100644
--- a/core/modules/user/src/Plugin/Block/UserLoginBlock.php
+++ b/core/modules/user/src/Plugin/Block/UserLoginBlock.php
@@ -25,7 +25,7 @@ class UserLoginBlock extends BlockBase {
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     $route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
     return ($account->isAnonymous() && !in_array($route_name, array('user.register', 'user.login', 'user.logout')));
   }
diff --git a/core/modules/user/src/Plugin/Condition/UserRole.php b/core/modules/user/src/Plugin/Condition/UserRole.php
index 8724489..c0383c7 100644
--- a/core/modules/user/src/Plugin/Condition/UserRole.php
+++ b/core/modules/user/src/Plugin/Condition/UserRole.php
@@ -35,7 +35,6 @@ public function buildConfigurationForm(array $form, array &$form_state) {
       '#default_value' => $this->configuration['roles'],
       '#options' => array_map('\Drupal\Component\Utility\String::checkPlain', user_role_names()),
       '#description' => $this->t('If you select no roles, the condition will evaluate to TRUE for all users.'),
-      '#required' => TRUE,
     );
     return $form;
   }
@@ -46,7 +45,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
   public function defaultConfiguration() {
     return array(
       'roles' => array(),
-    );
+    ) + parent::defaultConfiguration();
   }
 
   /**
@@ -81,8 +80,11 @@ public function summary() {
    * {@inheritdoc}
    */
   public function evaluate() {
+    if (empty($this->configuration['roles']) && !$this->configuration['negate']) {
+      return TRUE;
+    }
     $user = $this->getContextValue('user');
-    return (bool) array_intersect($this->configuration['roles'], $user->getRoles());
+    return array_intersect($this->configuration['roles'], $user->getRoles());
   }
 
 }
diff --git a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
index b0bfdba..5a63e76 100644
--- a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
+++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
@@ -91,7 +91,7 @@ public static function create(ContainerInterface $container, array $configuratio
   /**
    * {@inheritdoc}
    */
-  public function access(AccountInterface $account) {
+  protected function blockAccess(AccountInterface $account) {
     return $this->view->access($this->displayID);
   }
 
diff --git a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php
index dd2d2e8..0475e23 100644
--- a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php
+++ b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php
@@ -109,11 +109,14 @@ protected function createBlock($plugin_id, array $settings = array()) {
         'max_age' => 0,
       ),
     );
-    foreach (array('region', 'id', 'theme', 'plugin', 'visibility', 'weight') as $key) {
+    foreach (array('region', 'id', 'theme', 'plugin', 'weight') as $key) {
       $values[$key] = $settings[$key];
       // Remove extra values that do not belong in the settings array.
       unset($settings[$key]);
     }
+    foreach ($settings['visibility'] as $id => $visibility) {
+      $settings['visibility'][$id]['id'] = $id;
+    }
     $values['settings'] = $settings;
     $block = entity_create('block', $values);
     $block->save();
diff --git a/core/modules/views/tests/src/Plugin/Block/ViewsBlockTest.php b/core/modules/views/tests/src/Plugin/Block/ViewsBlockTest.php
index eb46cb3..34a0b99 100644
--- a/core/modules/views/tests/src/Plugin/Block/ViewsBlockTest.php
+++ b/core/modules/views/tests/src/Plugin/Block/ViewsBlockTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\views\Tests\Plugin\Block {
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\Tests\UnitTestCase;
 use Drupal\views\Plugin\Block\ViewsBlock;
 use Drupal\block\Plugin\views\display\Block;
@@ -71,6 +72,10 @@ public static function getInfo() {
    */
   protected function setUp() {
     parent::setUp(); // TODO: Change the autogenerated stub
+    $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
+    $container = new ContainerBuilder();
+    $container->set('module_handler', $module_handler);
+    \Drupal::setContainer($container);
 
     $this->executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
       ->disableOriginalConstructor()
@@ -128,6 +133,10 @@ public function testBuild() {
 
     $definition['provider'] = 'views';
     $plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
+    $reflector = new \ReflectionClass($plugin);
+    $property = $reflector->getProperty('conditionPluginManager');
+    $property->setAccessible(TRUE);
+    $property->setValue($plugin, $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface'));
 
     $this->assertEquals($build, $plugin->build());
   }
@@ -150,6 +159,10 @@ public function testBuildFailed() {
 
     $definition['provider'] = 'views';
     $plugin = new ViewsBlock($config, $block_id, $definition, $this->executableFactory, $this->storage, $this->account);
+    $reflector = new \ReflectionClass($plugin);
+    $property = $reflector->getProperty('conditionPluginManager');
+    $property->setAccessible(TRUE);
+    $property->setValue($plugin, $this->getMock('Drupal\Core\Executable\ExecutableManagerInterface'));
 
     $this->assertEquals(array(), $plugin->build());
   }
diff --git a/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php b/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php
index 3384b0f..1a405d9 100644
--- a/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php
+++ b/core/modules/views_ui/src/Tests/OverrideDisplaysTest.php
@@ -120,9 +120,9 @@ function testWizardMixedDefaultOverriddenDisplays() {
     // presence/absence of the view's title in both the page and the block).
     $this->drupalPlaceBlock("views_block:{$view['id']}-block_1", array(
       'visibility' => array(
-        'path' => array(
-          'visibility' => BLOCK_VISIBILITY_NOTLISTED,
+        'request_path' => array(
           'pages' => $view['page[path]'],
+          'negate' => TRUE,
         ),
       ),
     ));
diff --git a/core/profiles/minimal/config/install/block.block.stark_admin.yml b/core/profiles/minimal/config/install/block.block.stark_admin.yml
index 5d5c2c1..ab167ad 100644
--- a/core/profiles/minimal/config/install/block.block.stark_admin.yml
+++ b/core/profiles/minimal/config/install/block.block.stark_admin.yml
@@ -6,17 +6,18 @@ langcode: en
 region: sidebar_first
 plugin: 'system_menu_block:admin'
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
   label: Administration
   provider: system
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types: {  }
 dependencies:
   entity:
     - system.menu.admin
diff --git a/core/profiles/minimal/config/install/block.block.stark_login.yml b/core/profiles/minimal/config/install/block.block.stark_login.yml
index 91ba3e0..adeed2b 100644
--- a/core/profiles/minimal/config/install/block.block.stark_login.yml
+++ b/core/profiles/minimal/config/install/block.block.stark_login.yml
@@ -6,17 +6,18 @@ langcode: en
 region: sidebar_first
 plugin: user_login_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
   label: 'User login'
   provider: user
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types: {  }
 dependencies:
   module:
     - user
diff --git a/core/profiles/minimal/config/install/block.block.stark_tools.yml b/core/profiles/minimal/config/install/block.block.stark_tools.yml
index 36481b3..8783843 100644
--- a/core/profiles/minimal/config/install/block.block.stark_tools.yml
+++ b/core/profiles/minimal/config/install/block.block.stark_tools.yml
@@ -6,17 +6,18 @@ langcode: en
 region: sidebar_first
 plugin: 'system_menu_block:tools'
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
   label: Tools
   provider: system
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types: {  }
 dependencies:
   entity:
     - system.menu.tools
diff --git a/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml b/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml
index 23cc5d0..cdb1aaf 100644
--- a/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_breadcrumbs.yml
@@ -6,19 +6,19 @@ langcode: en
 region: '-1'
 plugin: system_breadcrumb_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_breadcrumb_block
   label: Breadcrumbs
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.bartik_content.yml b/core/profiles/standard/config/install/block.block.bartik_content.yml
index dd89d12..a7b20eb 100644
--- a/core/profiles/standard/config/install/block.block.bartik_content.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_content.yml
@@ -6,19 +6,19 @@ langcode: en
 region: content
 plugin: system_main_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_main_block
   label: 'Main page content'
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.bartik_footer.yml b/core/profiles/standard/config/install/block.block.bartik_footer.yml
index ef96ea9..42e8e2a 100644
--- a/core/profiles/standard/config/install/block.block.bartik_footer.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_footer.yml
@@ -6,19 +6,19 @@ langcode: en
 region: footer
 plugin: 'system_menu_block:footer'
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: 'system_menu_block:footer'
   label: 'Footer menu'
   provider: system
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   entity:
     - system.menu.footer
diff --git a/core/profiles/standard/config/install/block.block.bartik_help.yml b/core/profiles/standard/config/install/block.block.bartik_help.yml
index 3e139c6..a4734d1 100644
--- a/core/profiles/standard/config/install/block.block.bartik_help.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_help.yml
@@ -6,19 +6,19 @@ langcode: en
 region: help
 plugin: system_help_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_help_block
   label: 'System Help'
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.bartik_login.yml b/core/profiles/standard/config/install/block.block.bartik_login.yml
index 1465ce8..120c4ac 100644
--- a/core/profiles/standard/config/install/block.block.bartik_login.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_login.yml
@@ -6,19 +6,19 @@ langcode: en
 region: sidebar_first
 plugin: user_login_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: user_login_block
   label: 'User login'
   provider: user
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - user
diff --git a/core/profiles/standard/config/install/block.block.bartik_powered.yml b/core/profiles/standard/config/install/block.block.bartik_powered.yml
index c722231..1962279 100644
--- a/core/profiles/standard/config/install/block.block.bartik_powered.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_powered.yml
@@ -6,19 +6,19 @@ langcode: en
 region: footer
 plugin: system_powered_by_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_powered_by_block
   label: 'Powered by Drupal'
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.bartik_search.yml b/core/profiles/standard/config/install/block.block.bartik_search.yml
index 7b00a70..1fec301 100644
--- a/core/profiles/standard/config/install/block.block.bartik_search.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_search.yml
@@ -6,19 +6,19 @@ langcode: en
 region: sidebar_first
 plugin: search_form_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: search_form_block
   label: Search
   provider: search
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - search
diff --git a/core/profiles/standard/config/install/block.block.bartik_tools.yml b/core/profiles/standard/config/install/block.block.bartik_tools.yml
index 12efff1..6e6b7e4 100644
--- a/core/profiles/standard/config/install/block.block.bartik_tools.yml
+++ b/core/profiles/standard/config/install/block.block.bartik_tools.yml
@@ -6,19 +6,19 @@ langcode: en
 region: sidebar_first
 plugin: 'system_menu_block:tools'
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: 'system_menu_block:tools'
   label: Tools
   provider: system
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   entity:
     - system.menu.tools
diff --git a/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml b/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml
index 844a546..cfc69f1 100644
--- a/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml
+++ b/core/profiles/standard/config/install/block.block.seven_breadcrumbs.yml
@@ -6,19 +6,19 @@ langcode: en
 region: '-1'
 plugin: system_breadcrumb_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_breadcrumb_block
   label: Breadcrumbs
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.seven_content.yml b/core/profiles/standard/config/install/block.block.seven_content.yml
index ec7a432..bfdbf8c 100644
--- a/core/profiles/standard/config/install/block.block.seven_content.yml
+++ b/core/profiles/standard/config/install/block.block.seven_content.yml
@@ -6,19 +6,19 @@ langcode: en
 region: content
 plugin: system_main_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_main_block
   label: 'Main page content'
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.seven_help.yml b/core/profiles/standard/config/install/block.block.seven_help.yml
index f54a908..245077f 100644
--- a/core/profiles/standard/config/install/block.block.seven_help.yml
+++ b/core/profiles/standard/config/install/block.block.seven_help.yml
@@ -6,19 +6,19 @@ langcode: en
 region: help
 plugin: system_help_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: system_help_block
   label: 'System Help'
   provider: system
   label_display: '0'
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - system
diff --git a/core/profiles/standard/config/install/block.block.seven_login.yml b/core/profiles/standard/config/install/block.block.seven_login.yml
index 9f4578c..430da80 100644
--- a/core/profiles/standard/config/install/block.block.seven_login.yml
+++ b/core/profiles/standard/config/install/block.block.seven_login.yml
@@ -6,19 +6,19 @@ langcode: en
 region: content
 plugin: user_login_block
 settings:
+  visibility:
+    request_path:
+      id: request_path
+      pages: ''
+    user_role:
+      id: user_role
+      roles: {  }
+    node_type:
+      id: node_type
+  id: user_login_block
   label: 'User login'
   provider: user
   label_display: visible
-visibility:
-  path:
-    visibility: 0
-    pages: ''
-  role:
-    roles: {  }
-  node_type:
-    types:
-      article: '0'
-      page: '0'
 dependencies:
   module:
     - user
diff --git a/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php b/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php
new file mode 100644
index 0000000..dc676c5
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php
@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Condition\ConditionAccessResolverTraitTest.
+ */
+
+namespace Drupal\Tests\Core\Condition;
+
+use Drupal\Core\Condition\ConditionAccessResolverTrait;
+use Drupal\Component\Plugin\Exception\PluginException;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests resolving a set of conditions.
+ *
+ * @coversDefaultClass \Drupal\Core\Condition\ConditionAccessResolverTrait
+ *
+ * @group Drupal
+ * @group Condition
+ */
+class ConditionAccessResolverTraitTest extends UnitTestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Tests resolving a set of conditions',
+      'description' => '',
+      'group' => 'Condition',
+    );
+  }
+
+  /**
+   * Tests the resolveConditions() method.
+   *
+   * @covers ::resolveConditions
+   *
+   * @dataProvider providerTestResolveConditions
+   */
+  public function testResolveConditions($conditions, $logic, $expected) {
+    $trait_object = new TestConditionAccessResolverTrait();
+    $this->assertEquals($expected, $trait_object->resolveConditions($conditions, $logic));
+  }
+
+  public function providerTestResolveConditions() {
+    $data = array();
+
+    $condition_true = $this->getMock('Drupal\Core\Condition\ConditionInterface');
+    $condition_true->expects($this->any())
+      ->method('execute')
+      ->will($this->returnValue(TRUE));
+    $condition_false = $this->getMock('Drupal\Core\Condition\ConditionInterface');
+    $condition_false->expects($this->any())
+      ->method('execute')
+      ->will($this->returnValue(FALSE));
+    $condition_exception = $this->getMock('Drupal\Core\Condition\ConditionInterface');
+    $condition_exception->expects($this->any())
+      ->method('execute')
+      ->will($this->throwException(new PluginException()));
+
+    $conditions = array();
+    $data[] = array($conditions, 'and', TRUE);
+    $data[] = array($conditions, 'or', FALSE);
+
+    $conditions = array($condition_false);
+    $data[] = array($conditions, 'or', FALSE);
+    $data[] = array($conditions, 'and', FALSE);
+
+    $conditions = array($condition_true);
+    $data[] = array($conditions, 'or', TRUE);
+    $data[] = array($conditions, 'and', TRUE);
+
+    $conditions = array($condition_true, $condition_false);
+    $data[] = array($conditions, 'or', TRUE);
+    $data[] = array($conditions, 'and', FALSE);
+
+    $conditions = array($condition_exception);
+    $data[] = array($conditions, 'or', FALSE);
+    $data[] = array($conditions, 'and', FALSE);
+
+    $conditions = array($condition_true, $condition_exception);
+    $data[] = array($conditions, 'or', TRUE);
+    $data[] = array($conditions, 'and', FALSE);
+
+    $conditions = array($condition_exception, $condition_true);
+    $data[] = array($conditions, 'or', TRUE);
+    $data[] = array($conditions, 'and', FALSE);
+
+    $conditions = array($condition_false, $condition_exception);
+    $data[] = array($conditions, 'or', FALSE);
+    $data[] = array($conditions, 'and', FALSE);
+
+    $conditions = array($condition_exception, $condition_false);
+    $data[] = array($conditions, 'or', FALSE);
+    $data[] = array($conditions, 'and', FALSE);
+    return $data;
+  }
+
+}
+
+class TestConditionAccessResolverTrait {
+  use \Drupal\Core\Condition\ConditionAccessResolverTrait {
+    resolveConditions as public;
+  }
+}
diff --git a/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
new file mode 100644
index 0000000..fa7c80c
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
@@ -0,0 +1,403 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Plugin\ContextHandlerTest.
+ */
+
+namespace Drupal\Tests\Core\Plugin;
+
+use Drupal\Component\Plugin\ConfigurablePluginInterface;
+use Drupal\Component\Plugin\ContextAwarePluginInterface;
+use Drupal\Core\Plugin\Context\ContextHandler;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * Tests the ContextHandler class.
+ *
+ * @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler
+ *
+ * @group Drupal
+ * @group Plugin
+ * @group Context
+ */
+class ContextHandlerTest extends UnitTestCase {
+
+  /**
+   * The typed data manager.
+   *
+   * @var \Drupal\Core\TypedData\TypedDataManager|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $typedDataManager;
+
+  /**
+   * The context handler.
+   *
+   * @var \Drupal\Core\Plugin\Context\ContextHandler
+   */
+  protected $contextHandler;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'ContextHandler',
+      'description' => 'Tests the ContextHandler',
+      'group' => 'Plugin API',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   *
+   * @covers ::__construct
+   */
+  protected function setUp() {
+    parent::setUp();
+
+    $this->typedDataManager = $this->getMockBuilder('Drupal\Core\TypedData\TypedDataManager')
+      ->disableOriginalConstructor()
+      ->getMock();
+    $this->typedDataManager->expects($this->any())
+      ->method('getDefaultConstraints')
+      ->will($this->returnValue(array()));
+    $this->contextHandler = new ContextHandler($this->typedDataManager);
+
+    $container = new ContainerBuilder();
+    $container->set('typed_data_manager', $this->typedDataManager);
+    \Drupal::setContainer($container);
+  }
+
+  /**
+   * @covers ::checkRequirements
+   *
+   * @dataProvider providerTestCheckRequirements
+   */
+  public function testCheckRequirements($contexts, $requirements, $expected) {
+    $this->assertSame($expected, $this->contextHandler->checkRequirements($contexts, $requirements));
+  }
+
+  /**
+   * Provides data for testCheckRequirements().
+   */
+  public function providerTestCheckRequirements() {
+    $requirement_optional = $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface');
+    $requirement_optional->expects($this->atLeastOnce())
+      ->method('isRequired')
+      ->will($this->returnValue(FALSE));
+
+    $requirement_any = $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface');
+    $requirement_any->expects($this->atLeastOnce())
+      ->method('isRequired')
+      ->will($this->returnValue(TRUE));
+    $requirement_any->expects($this->atLeastOnce())
+      ->method('getDataType')
+      ->will($this->returnValue('any'));
+    $requirement_any->expects($this->atLeastOnce())
+      ->method('getConstraints')
+      ->will($this->returnValue(array()));
+
+    $context_any = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_any->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array()));
+
+    $requirement_specific = $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface');
+    $requirement_specific->expects($this->atLeastOnce())
+      ->method('isRequired')
+      ->will($this->returnValue(TRUE));
+    $requirement_specific->expects($this->atLeastOnce())
+      ->method('getDataType')
+      ->will($this->returnValue('foo'));
+    $requirement_specific->expects($this->atLeastOnce())
+      ->method('getConstraints')
+      ->will($this->returnValue(array('bar' => 'baz')));
+
+    $context_constraint_mismatch = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_constraint_mismatch->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'foo')));
+    $context_datatype_mismatch = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_datatype_mismatch->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'fuzzy')));
+
+    $context_specific = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_specific->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'foo', 'constraints' => array('bar' => 'baz'))));
+
+    $data = array();
+    $data[] = array(array(), array(), TRUE);
+    $data[] = array(array(), array($requirement_any), FALSE);
+    $data[] = array(array(), array($requirement_optional), TRUE);
+    $data[] = array(array(), array($requirement_any, $requirement_optional), FALSE);
+    $data[] = array(array($context_any), array($requirement_any), TRUE);
+    $data[] = array(array($context_constraint_mismatch), array($requirement_specific), FALSE);
+    $data[] = array(array($context_datatype_mismatch), array($requirement_specific), FALSE);
+    $data[] = array(array($context_specific), array($requirement_specific), TRUE);
+
+    return $data;
+  }
+
+  /**
+   * @covers ::getMatchingContexts
+   *
+   * @dataProvider providerTestGetMatchingContexts
+   */
+  public function testGetMatchingContexts($contexts, $requirement, $expected = NULL) {
+    if (is_null($expected)) {
+      $expected = $contexts;
+    }
+    $this->assertSame($expected, $this->contextHandler->getMatchingContexts($contexts, $requirement));
+  }
+
+  /**
+   * Provides data for testGetMatchingContexts().
+   */
+  public function providerTestGetMatchingContexts() {
+    $requirement_any = $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface');
+    $requirement_any->expects($this->atLeastOnce())
+      ->method('isRequired')
+      ->will($this->returnValue(TRUE));
+    $requirement_any->expects($this->atLeastOnce())
+      ->method('getDataType')
+      ->will($this->returnValue('any'));
+    $requirement_any->expects($this->atLeastOnce())
+      ->method('getConstraints')
+      ->will($this->returnValue(array()));
+    $requirement_specific = $this->getMock('Drupal\Core\TypedData\DataDefinitionInterface');
+    $requirement_specific->expects($this->atLeastOnce())
+      ->method('isRequired')
+      ->will($this->returnValue(TRUE));
+    $requirement_specific->expects($this->atLeastOnce())
+      ->method('getDataType')
+      ->will($this->returnValue('foo'));
+    $requirement_specific->expects($this->atLeastOnce())
+      ->method('getConstraints')
+      ->will($this->returnValue(array('bar' => 'baz')));
+
+    $context_any = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_any->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array()));
+    $context_constraint_mismatch = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_constraint_mismatch->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'foo')));
+    $context_datatype_mismatch = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_datatype_mismatch->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'fuzzy')));
+    $context_specific = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_specific->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'foo', 'constraints' => array('bar' => 'baz'))));
+
+    $data = array();
+    // No context will return no valid contexts.
+    $data[] = array(array(), $requirement_any);
+    // A context with a generic matching requirement is valid.
+    $data[] = array(array($context_any), $requirement_any);
+    // A context with a specific matching requirement is valid.
+    $data[] = array(array($context_specific), $requirement_specific);
+
+    // A context with a mismatched constraint is invalid.
+    $data[] = array(array($context_constraint_mismatch), $requirement_specific, array());
+    // A context with a mismatched datatype is invalid.
+    $data[] = array(array($context_datatype_mismatch), $requirement_specific, array());
+
+    return $data;
+  }
+
+  /**
+   * @covers ::filterPluginDefinitionsByContexts
+   *
+   * @dataProvider providerTestFilterPluginDefinitionsByContexts
+   */
+  public function testFilterPluginDefinitionsByContexts($contexts, $definitions, $expected, $typed_data_definition = NULL) {
+    if ($typed_data_definition) {
+      $this->typedDataManager->expects($this->atLeastOnce())
+        ->method('getDefinition')
+        ->will($this->returnValueMap($typed_data_definition));
+    }
+
+    $this->assertSame($expected, $this->contextHandler->filterPluginDefinitionsByContexts($contexts, $definitions));
+  }
+
+  /**
+   * Provides data for testFilterPluginDefinitionsByContexts().
+   */
+  public function providerTestFilterPluginDefinitionsByContexts() {
+    $context = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context->expects($this->atLeastOnce())
+      ->method('getContextDefinition')
+      ->will($this->returnValue(array('type' => 'expected_data_type', 'constraints' => array('expected_constraint_name' => 'expected_constraint_value'))));
+
+    $data = array();
+
+    $plugins = array();
+    // No context and no plugins, no plugins available.
+    $data[] = array(array(), $plugins, array());
+
+    $plugins = array('expected_plugin' => array());
+    // No context, all plugins available.
+    $data[] = array(array(), $plugins, $plugins);
+
+    $plugins = array('expected_plugin' => array('context' => array()));
+    // No context, all plugins available.
+    $data[] = array(array(), $plugins, $plugins);
+
+    $plugins = array('expected_plugin' => array('context' => array('context1' => array('type' => 'expected_data_type'))));
+    // Missing context, no plugins available.
+    $data[] = array(array(), $plugins, array());
+    // Satisfied context, all plugins available.
+    $data[] = array(array($context), $plugins, $plugins);
+
+    $plugins = array('expected_plugin' => array('context' => array('context1' => array('type' => 'expected_data_type', 'constraints' => array('mismatched_constraint_name' => 'mismatched_constraint_value')))));
+    // Mismatched constraints, no plugins available.
+    $data[] = array(array($context), $plugins, array());
+
+    $plugins = array('expected_plugin' => array('context' => array('context1' => array('type' => 'expected_data_type', 'constraints' => array('expected_constraint_name' => 'expected_constraint_value')))));
+    // Satisfied context with constraint, all plugins available.
+    $data[] = array(array($context), $plugins, $plugins);
+
+    $typed_data = array(array('expected_data_type', TRUE, array('required' => FALSE)));
+    // Optional unsatisfied context from TypedData, all plugins available.
+    $data[] = array(array(), $plugins, $plugins, $typed_data);
+
+    $typed_data = array(array('expected_data_type', TRUE, array('required' => TRUE)));
+    // Required unsatisfied context from TypedData, no plugins available.
+    $data[] = array(array(), $plugins, array(), $typed_data);
+
+    $typed_data = array(array('expected_data_type', TRUE, array('constraints' => array('mismatched_constraint_name' => 'mismatched_constraint_value'), 'required' => FALSE)));
+    // Optional mismatched constraint from TypedData, all plugins available.
+    $data[] = array(array(), $plugins, $plugins, $typed_data);
+
+    $typed_data = array(array('expected_data_type', TRUE, array('constraints' => array('mismatched_constraint_name' => 'mismatched_constraint_value'), 'required' => TRUE)));
+    // Required mismatched constraint from TypedData, no plugins available.
+    $data[] = array(array(), $plugins, array(), $typed_data);
+
+    $typed_data = array(array('expected_data_type', TRUE, array('constraints' => array('expected_constraint_name' => 'expected_constraint_value'))));
+    // Satisfied constraint from TypedData, all plugins available.
+    $data[] = array(array($context), $plugins, $plugins, $typed_data);
+
+    $plugins = array(
+      'unexpected_plugin' => array('context' => array('context1' => array('type' => 'unexpected_data_type', 'constraints' => array('mismatched_constraint_name' => 'mismatched_constraint_value')))),
+      'expected_plugin' => array('context' => array('context2' => array('type' => 'expected_data_type'))),
+    );
+    $typed_data = array(
+      array('unexpected_data_type', TRUE, array()),
+      array('expected_data_type', TRUE, array('constraints' => array('expected_constraint_name' => 'expected_constraint_value'))),
+    );
+    // Context only satisfies one plugin.
+    $data[] = array(array($context), $plugins, array('expected_plugin' => $plugins['expected_plugin']), $typed_data);
+
+    return $data;
+  }
+
+  /**
+   * @covers ::applyContextMapping
+   */
+  public function testApplyContextMapping() {
+    $context_hit = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_hit->expects($this->atLeastOnce())
+      ->method('getContextValue')
+      ->will($this->returnValue(array('foo')));
+    $context_miss = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context_miss->expects($this->never())
+      ->method('getContextValue');
+
+    $contexts = array(
+      'hit' => $context_hit,
+      'miss' => $context_miss,
+    );
+
+    $plugin = $this->getMock('Drupal\Component\Plugin\ContextAwarePluginInterface');
+    $plugin->expects($this->once())
+      ->method('getContextDefinitions')
+      ->will($this->returnValue(array('hit' => 'hit')));
+    $plugin->expects($this->once())
+      ->method('setContextValue')
+      ->with('hit', array('foo'));
+
+    $this->contextHandler->applyContextMapping($plugin, $contexts);
+  }
+
+  /**
+   * @covers ::applyContextMapping
+   */
+  public function testApplyContextMappingConfigurable() {
+    $context = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context->expects($this->never())
+      ->method('getContextValue');
+
+    $contexts = array(
+      'name' => $context,
+    );
+
+    $plugin = $this->getMock('Drupal\Tests\Core\Plugin\TestConfigurableContextAwarePluginInterface');
+    $plugin->expects($this->once())
+      ->method('getContextDefinitions')
+      ->will($this->returnValue(array('hit' => 'hit')));
+    $plugin->expects($this->never())
+      ->method('setContextValue');
+
+    $this->contextHandler->applyContextMapping($plugin, $contexts);
+  }
+
+  /**
+   * @covers ::applyContextMapping
+   */
+  public function testApplyContextMappingConfigurableAssigned() {
+    $context = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context->expects($this->atLeastOnce())
+      ->method('getContextValue')
+      ->will($this->returnValue(array('foo')));
+
+    $contexts = array(
+      'name' => $context,
+    );
+
+    $plugin = $this->getMock('Drupal\Tests\Core\Plugin\TestConfigurableContextAwarePluginInterface');
+    $plugin->expects($this->once())
+      ->method('getContextDefinitions')
+      ->will($this->returnValue(array('hit' => 'hit')));
+    $plugin->expects($this->once())
+      ->method('setContextValue')
+      ->with('hit', array('foo'));
+
+    $this->contextHandler->applyContextMapping($plugin, $contexts, array('name' => 'hit'));
+  }
+
+  /**
+   * @covers ::applyContextMapping
+   *
+   * @expectedException \Drupal\Component\Plugin\Exception\ContextException
+   * @expectedExceptionMessage Assigned contexts were not satisfied: miss
+   */
+  public function testApplyContextMappingConfigurableAssignedMiss() {
+    $context = $this->getMock('Drupal\Component\Plugin\Context\ContextInterface');
+    $context->expects($this->never())
+      ->method('getContextValue');
+
+    $contexts = array(
+      'name' => $context,
+    );
+
+    $plugin = $this->getMock('Drupal\Tests\Core\Plugin\TestConfigurableContextAwarePluginInterface');
+    $plugin->expects($this->once())
+      ->method('getContextDefinitions')
+      ->will($this->returnValue(array('hit' => 'hit')));
+    $plugin->expects($this->never())
+      ->method('setContextValue');
+
+    $this->contextHandler->applyContextMapping($plugin, $contexts, array('name' => 'miss'));
+  }
+
+}
+
+interface TestConfigurableContextAwarePluginInterface extends ContextAwarePluginInterface, ConfigurablePluginInterface {
+}
