diff --git a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
index 5237d0d..0b4d200 100644
--- a/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
+++ b/core/lib/Drupal/Core/Condition/ConditionPluginBase.php
@@ -73,6 +73,9 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
    */
   public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
     $this->configuration['negate'] = $form_state->getValue('negate');
+    if ($form_state->hasValue('context_mapping')) {
+      $this->setContextMapping($form_state->getValue('context_mapping'));
+    }
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Form/FormState.php b/core/lib/Drupal/Core/Form/FormState.php
index a71e342..23cd7b7 100644
--- a/core/lib/Drupal/Core/Form/FormState.php
+++ b/core/lib/Drupal/Core/Form/FormState.php
@@ -16,6 +16,8 @@
  */
 class FormState implements FormStateInterface {
 
+  use FormStateValuesTrait;
+
   /**
    * Tracks if any errors have been set on any form.
    *
@@ -985,67 +987,6 @@ public function &getValues() {
   /**
    * {@inheritdoc}
    */
-  public function &getValue($key, $default = NULL) {
-    $exists = NULL;
-    $value = &NestedArray::getValue($this->getValues(), (array) $key, $exists);
-    if (!$exists) {
-      $value = $default;
-    }
-    return $value;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function setValues(array $values) {
-    $this->values = $values;
-    return $this;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function setValue($key, $value) {
-    NestedArray::setValue($this->getValues(), (array) $key, $value, TRUE);
-    return $this;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function unsetValue($key) {
-    NestedArray::unsetValue($this->getValues(), (array) $key);
-    return $this;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function hasValue($key) {
-    $exists = NULL;
-    $value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
-    return $exists && isset($value);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function isValueEmpty($key) {
-    $exists = NULL;
-    $value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
-    return !$exists || empty($value);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public function setValueForElement(array $element, $value) {
-    return $this->setValue($element['#parents'], $value);
-  }
-
-  /**
-   * {@inheritdoc}
-   */
   public function setResponse(Response $response) {
     $this->response = $response;
     return $this;
diff --git a/core/lib/Drupal/Core/Form/FormStateDecoratorBase.php b/core/lib/Drupal/Core/Form/FormStateDecoratorBase.php
new file mode 100644
index 0000000..da24cb1
--- /dev/null
+++ b/core/lib/Drupal/Core/Form/FormStateDecoratorBase.php
@@ -0,0 +1,697 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Form\FormStateDecorator.
+ */
+
+namespace Drupal\Core\Form;
+
+use Drupal\Core\Url;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * Decorates another form state.
+ */
+abstract class FormStateDecoratorBase implements FormStateInterface {
+
+  /**
+   * The decorated form state.
+   *
+   * @var \Drupal\Core\Form\FormStateInterface
+   */
+  protected $decoratedFormState;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setFormState(array $form_state_additions) {
+    $this->decoratedFormState->setFormState($form_state_additions);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setAlwaysProcess($always_process = TRUE) {
+    $this->decoratedFormState->setAlwaysProcess($always_process);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getAlwaysProcess() {
+    return $this->decoratedFormState->getAlwaysProcess();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setButtons(array $buttons) {
+    $this->decoratedFormState->setButtons($buttons);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getButtons() {
+    return $this->decoratedFormState->getButtons();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setCached($cache = TRUE) {
+    $this->decoratedFormState->setCached($cache);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isCached() {
+    return $this->decoratedFormState->isCached();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function disableCache() {
+    $this->decoratedFormState->disableCache();
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setExecuted() {
+    $this->decoratedFormState->setExecuted();
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isExecuted() {
+    return $this->decoratedFormState->isExecuted();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setGroups(array $groups) {
+    $this->decoratedFormState->setGroups($groups);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getGroups() {
+    return $this->decoratedFormState->getGroups();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setHasFileElement($has_file_element = TRUE) {
+    $this->decoratedFormState->setHasFileElement($has_file_element);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function hasFileElement() {
+    return $this->decoratedFormState->hasFileElement();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setLimitValidationErrors($limit_validation_errors) {
+    $this->decoratedFormState->setLimitValidationErrors($limit_validation_errors);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getLimitValidationErrors() {
+    return $this->decoratedFormState->getLimitValidationErrors();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setMethod($method) {
+    $this->decoratedFormState->setMethod($method);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isMethodType($method_type) {
+    return $this->decoratedFormState->isMethodType($method_type);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRequestMethod($method) {
+    $this->decoratedFormState->setRequestMethod($method);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setValidationEnforced($must_validate = TRUE) {
+    $this->decoratedFormState->setValidationEnforced($must_validate);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isValidationEnforced() {
+    return $this->decoratedFormState->isValidationEnforced();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function disableRedirect($no_redirect = TRUE) {
+    $this->decoratedFormState->disableRedirect($no_redirect);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isRedirectDisabled() {
+    return $this->decoratedFormState->isRedirectDisabled();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setProcessInput($process_input = TRUE) {
+    $this->decoratedFormState->setProcessInput($process_input);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isProcessingInput() {
+    return $this->decoratedFormState->isProcessingInput();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setProgrammed($programmed = TRUE) {
+    $this->decoratedFormState->setProgrammed($programmed);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isProgrammed() {
+    return $this->decoratedFormState->isProgrammed();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setProgrammedBypassAccessCheck($programmed_bypass_access_check = TRUE) {
+    $this->decoratedFormState->setProgrammedBypassAccessCheck($programmed_bypass_access_check);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isBypassingProgrammedAccessChecks() {
+    return $this->decoratedFormState->isBypassingProgrammedAccessChecks();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRebuildInfo(array $rebuild_info) {
+    $this->decoratedFormState->setRebuildInfo($rebuild_info);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRebuildInfo() {
+    return $this->decoratedFormState->getRebuildInfo();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function addRebuildInfo($property, $value) {
+    $this->decoratedFormState->addRebuildInfo($property, $value);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setStorage(array $storage) {
+    $this->decoratedFormState->setStorage($storage);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getStorage() {
+    return $this->decoratedFormState->getStorage();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setSubmitHandlers(array $submit_handlers) {
+    $this->decoratedFormState->setSubmitHandlers($submit_handlers);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getSubmitHandlers() {
+    return $this->decoratedFormState->getSubmitHandlers();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setSubmitted() {
+    $this->decoratedFormState->setSubmitted();
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isSubmitted() {
+    return $this->decoratedFormState->isSubmitted();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setTemporary(array $temporary) {
+    $this->decoratedFormState->setTemporary($temporary);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getTemporary() {
+    return $this->decoratedFormState->getTemporary();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getTemporaryValue($key) {
+    return $this->decoratedFormState->getTemporaryValue($key);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setTemporaryValue($key, $value) {
+    $this->decoratedFormState->setTemporaryValue($key, $value);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function hasTemporaryValue($key) {
+    return $this->decoratedFormState->hasTemporaryValue($key);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setTriggeringElement($triggering_element) {
+    $this->decoratedFormState->setTriggeringElement($triggering_element);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getTriggeringElement() {
+    return $this->decoratedFormState->getTriggeringElement();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setValidateHandlers(array $validate_handlers) {
+    $this->decoratedFormState->setValidateHandlers($validate_handlers);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getValidateHandlers() {
+    return $this->decoratedFormState->getValidateHandlers();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setValidationComplete($validation_complete = TRUE) {
+    $this->decoratedFormState->setValidationComplete($validation_complete);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isValidationComplete() {
+    return $this->decoratedFormState->isValidationComplete();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function loadInclude($module, $type, $name = NULL) {
+    return $this->decoratedFormState->loadInclude($module, $type, $name);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCacheableArray() {
+    return $this->decoratedFormState->getCacheableArray();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setCompleteForm(array &$complete_form) {
+    $this->decoratedFormState->setCompleteForm($complete_form);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getCompleteForm() {
+    return $this->decoratedFormState->getCompleteForm();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &get($property) {
+    return $this->decoratedFormState->get($property);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function set($property, $value) {
+    $this->decoratedFormState->set($property, $value);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function has($property) {
+    return $this->decoratedFormState->has($property);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setBuildInfo(array $build_info) {
+    $this->decoratedFormState->setBuildInfo($build_info);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getBuildInfo() {
+    return $this->decoratedFormState->getBuildInfo();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function addBuildInfo($property, $value) {
+    $this->decoratedFormState->addBuildInfo($property, $value);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getUserInput() {
+    return $this->decoratedFormState->getUserInput();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUserInput(array $user_input) {
+    $this->decoratedFormState->setUserInput($user_input);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getValues() {
+    return $this->decoratedFormState->getValues();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setResponse(Response $response) {
+    $this->decoratedFormState->setResponse($response);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getResponse() {
+    return $this->decoratedFormState->getResponse();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRedirect($route_name, array $route_parameters = [], array $options = []) {
+    $this->decoratedFormState->setRedirect($route_name, $route_parameters, $options);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRedirectUrl(Url $url) {
+    $this->decoratedFormState->setRedirectUrl($url);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getRedirect() {
+    return $this->decoratedFormState->getRedirect();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function hasAnyErrors() {
+    return FormState::hasAnyErrors();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setErrorByName($name, $message = '') {
+    $this->decoratedFormState->setErrorByName($name, $message);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setError(array &$element, $message = '') {
+    $this->decoratedFormState->setError($element, $message);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function clearErrors() {
+    $this->decoratedFormState->clearErrors();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getError(array $element) {
+    return $this->decoratedFormState->getError($element);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getErrors() {
+    return $this->decoratedFormState->getErrors();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setRebuild($rebuild = TRUE) {
+    $this->decoratedFormState->setRebuild($rebuild);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function isRebuilding() {
+    return $this->decoratedFormState->isRebuilding();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setInvalidToken($invalid_token) {
+    $this->decoratedFormState->setInvalidToken($invalid_token);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function hasInvalidToken() {
+    return $this->decoratedFormState->hasInvalidToken();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function prepareCallback($callback) {
+    return $this->decoratedFormState->prepareCallback($callback);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setFormObject(FormInterface $form_object) {
+    $this->decoratedFormState->setFormObject($form_object);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormObject() {
+    return $this->decoratedFormState->getFormObject();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCleanValueKeys() {
+    return $this->decoratedFormState->getCleanValueKeys();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setCleanValueKeys(array $cleanValueKeys) {
+    $this->decoratedFormState->setCleanValueKeys($cleanValueKeys);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function addCleanValueKey($cleanValueKey) {
+    $this->decoratedFormState->addCleanValueKey($cleanValueKey);
+
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function cleanValues() {
+    $this->decoratedFormState->cleanValues();
+
+    return $this;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Form/FormStateValuesTrait.php b/core/lib/Drupal/Core/Form/FormStateValuesTrait.php
new file mode 100644
index 0000000..6626beb
--- /dev/null
+++ b/core/lib/Drupal/Core/Form/FormStateValuesTrait.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Form\FormStateValuesTrait.
+ */
+
+namespace Drupal\Core\Form;
+
+use Drupal\Component\Utility\NestedArray;
+
+/**
+ * Provides methods to manage form state values.
+ *
+ * @see \Drupal\Core\Form\FormStateInterface
+ *
+ * @ingroup form_api
+ */
+trait FormStateValuesTrait {
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::getValues()
+   */
+  abstract public function &getValues();
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::getValue()
+   */
+  public function &getValue($key, $default = NULL) {
+    $exists = NULL;
+    $value = &NestedArray::getValue($this->getValues(), (array) $key, $exists);
+    if (!$exists) {
+      $value = $default;
+    }
+    return $value;
+  }
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::setValues()
+   */
+  public function setValues(array $values) {
+    $existing_values = &$this->getValues();
+    $existing_values = $values;
+    return $this;
+  }
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::setValue()
+   */
+  public function setValue($key, $value) {
+    NestedArray::setValue($this->getValues(), (array) $key, $value, TRUE);
+    return $this;
+  }
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::unsetValue()
+   */
+  public function unsetValue($key) {
+    NestedArray::unsetValue($this->getValues(), (array) $key);
+    return $this;
+  }
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::hasValue()
+   */
+  public function hasValue($key) {
+    $exists = NULL;
+    $value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
+    return $exists && isset($value);
+  }
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::isValueEmpty()
+   */
+  public function isValueEmpty($key) {
+    $exists = NULL;
+    $value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
+    return !$exists || empty($value);
+  }
+
+  /**
+   * @see \Drupal\Core\Form\FormStateInterface::setValueForElement()
+   */
+  public function setValueForElement(array $element, $value) {
+    return $this->setValue($element['#parents'], $value);
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Form/SubformState.php b/core/lib/Drupal/Core/Form/SubformState.php
new file mode 100644
index 0000000..e54ac21
--- /dev/null
+++ b/core/lib/Drupal/Core/Form/SubformState.php
@@ -0,0 +1,116 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Form\SubformState.
+ */
+
+namespace Drupal\Core\Form;
+
+use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Render\Element;
+
+/**
+ * Stores information about the state of a subform.
+ */
+class SubformState extends FormStateDecoratorBase implements SubformStateInterface {
+
+  use FormStateValuesTrait;
+
+  /**
+   * The subform.
+   *
+   * @var mixed[]
+   */
+  protected $subform;
+
+  /**
+   * Constructs a new instance.
+   *
+   * @param mixed[] $subform
+   *   The subform for which to create a form state.
+   * @param \Drupal\Core\Form\FormStateInterface $parent_form_state
+   *   The parent form state.
+   */
+  protected function __construct(array &$subform, FormStateInterface $parent_form_state) {
+    $this->decoratedFormState = $parent_form_state;
+    $this->subform = $subform;
+  }
+
+  /**
+   * Creates a new instance for a subform.
+   *
+   * @param mixed[] $subform
+   *   The subform for which to create a form state.
+   * @param \Drupal\Core\Form\FormStateInterface $parent_form_state
+   *   The parent form state.
+   *
+   * @return static
+   */
+  public static function createForSubform(array &$subform, FormStateInterface $parent_form_state) {
+    return new static($subform, $parent_form_state);
+  }
+
+  /**
+   * Gets a subform property value.
+   *
+   * @param string $property
+   *   The property name.
+   *
+   * @return mixed
+   *
+   * @throws \InvalidArgumentException
+   *   Thrown when the requested property does not exist.
+   */
+  protected function getSubformProperty($property) {
+    if (!array_key_exists($property, $this->subform)) {
+      throw new \InvalidArgumentException(sprintf('The subform must contain the %s property. Try calling this method from a #process callback instead.', $property));
+    }
+
+    return $this->subform[$property];
+  }
+
+  /**
+   * Gets the subform's parents.
+   *
+   * @return string[]
+   *   The parent keys (#array_parents).
+   */
+  protected function getArrayParents() {
+    return $this->getSubformProperty('#array_parents');
+  }
+
+  /**
+   * Gets the subform state's parents.
+   *
+   * @return string[]
+   *   The parent keys (#parents).
+   */
+  protected function getParents() {
+    return $this->getSubformProperty('#parents');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getValues() {
+    $exists = NULL;
+    $values = &NestedArray::getValue(parent::getValues(), $this->getParents(), $exists);
+    if (!$exists) {
+      $values = [];
+    }
+    elseif (!is_array($values)) {
+      throw new \UnexpectedValueException('The form state values do not belong to the subform.');
+    }
+
+    return $values;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getCompleteFormState() {
+    return $this->decoratedFormState instanceof SubformStateInterface ? $this->decoratedFormState->getCompleteFormState() : $this->decoratedFormState;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Form/SubformStateInterface.php b/core/lib/Drupal/Core/Form/SubformStateInterface.php
new file mode 100644
index 0000000..f837a21
--- /dev/null
+++ b/core/lib/Drupal/Core/Form/SubformStateInterface.php
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Form\SubformStateInterface.
+ */
+
+namespace Drupal\Core\Form;
+
+
+/**
+ * Stores information about the state of a subform.
+ */
+interface SubformStateInterface extends FormStateInterface {
+
+  /**
+   * Gets the complete form state.
+   *
+   * @return \Drupal\Core\Form\FormStateInterface
+   *
+   * @deprecated Deprecated as of Drupal 8.1.x. Scheduled for removal before
+   *   Drupal 9.0.0. Subforms should not depend on another form's form state,
+   *   and any dependencies should be passed on through the forms' API methods.
+   */
+  public function getCompleteFormState();
+
+}
diff --git a/core/lib/Drupal/Core/Plugin/PluginFormInterface.php b/core/lib/Drupal/Core/Plugin/PluginFormInterface.php
index 06dbbad..7e1fbba 100644
--- a/core/lib/Drupal/Core/Plugin/PluginFormInterface.php
+++ b/core/lib/Drupal/Core/Plugin/PluginFormInterface.php
@@ -32,7 +32,9 @@
    * @param array $form
    *   An associative array containing the initial structure of the plugin form.
    * @param \Drupal\Core\Form\FormStateInterface $form_state
-   *   The current state of the complete form.
+   *   The current state of the form. Calling code should pass on a sub form
+   *   state created through
+   *   \Drupal\Core\Form\SubformState::createForSubform().
    *
    * @return array
    *   The form structure.
@@ -46,7 +48,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
    *   An associative array containing the structure of the plugin form as built
    *   by static::buildConfigurationForm().
    * @param \Drupal\Core\Form\FormStateInterface $form_state
-   *   The current state of the complete form.
+   *   The current state of the form. Calling code should pass on a sub form
+   *   state created through
+   *   \Drupal\Core\Form\SubformState::createForSubform().
    */
   public function validateConfigurationForm(array &$form, FormStateInterface $form_state);
 
@@ -57,7 +61,9 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
    *   An associative array containing the structure of the plugin form as built
    *   by static::buildConfigurationForm().
    * @param \Drupal\Core\Form\FormStateInterface $form_state
-   *   The current state of the complete form.
+   *   The current state of the form. Calling code should pass on a sub form
+   *   state created through
+   *   \Drupal\Core\Form\SubformState::createForSubform().
    */
   public function submitConfigurationForm(array &$form, FormStateInterface $form_state);
 
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index 50e4d38..d4daa95 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -14,6 +14,7 @@
 use Drupal\Core\Extension\ThemeHandlerInterface;
 use Drupal\Core\Form\FormState;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Form\SubformState;
 use Drupal\Core\Language\LanguageManagerInterface;
 use Drupal\Core\Plugin\ContextAwarePluginInterface;
 use Drupal\Core\Plugin\Context\ContextRepositoryInterface;
@@ -125,7 +126,9 @@ public function form(array $form, FormStateInterface $form_state) {
     $form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());
 
     $form['#tree'] = TRUE;
-    $form['settings'] = $entity->getPlugin()->buildConfigurationForm(array(), $form_state);
+    $form['settings'] = [];
+    $subform_state = SubformState::createForSubform($form['settings'], $form_state);
+    $form['settings'] = $entity->getPlugin()->buildConfigurationForm($form['settings'], $subform_state);
     $form['visibility'] = $this->buildVisibilityInterface([], $form_state);
 
     // If creating a new block, calculate a safe default machine name.
@@ -285,11 +288,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
 
     // 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 = (new FormState())->setValues($form_state->getValue('settings'));
-    // Call the plugin validate handler.
-    $this->entity->getPlugin()->validateConfigurationForm($form, $settings);
-    // Update the original form values.
-    $form_state->setValue('settings', $settings->getValues());
+    $this->entity->getPlugin()->validateConfigurationForm($form['settings'], SubformState::createForSubform($form['settings'], $form_state));
     $this->validateVisibility($form, $form_state);
   }
 
@@ -313,11 +312,7 @@ protected function validateVisibility(array $form, FormStateInterface $form_stat
 
       // Allow the condition to validate the form.
       $condition = $form_state->get(['conditions', $condition_id]);
-      $condition_values = (new FormState())
-        ->setValues($values);
-      $condition->validateConfigurationForm($form, $condition_values);
-      // Update the original form values.
-      $form_state->setValue(['visibility', $condition_id], $condition_values->getValues());
+      $condition->validateConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form_state));
     }
   }
 
@@ -330,34 +325,27 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $entity = $this->entity;
     // The Block Entity form puts all block plugin form elements in the
     // settings form element, so just pass that to the block for submission.
-    // @todo Find a way to avoid this manipulation.
-    $settings = (new FormState())->setValues($form_state->getValue('settings'));
-
+    $sub_form_state = SubformState::createForSubform($form['settings'], $form_state);
     // Call the plugin submit handler.
-    $entity->getPlugin()->submitConfigurationForm($form, $settings);
+    $entity->getPlugin()->submitConfigurationForm($form['settings'], $sub_form_state);
     $block = $entity->getPlugin();
     // If this block is context-aware, set the context mapping.
     if ($block instanceof ContextAwarePluginInterface && $block->getContextDefinitions()) {
-      $context_mapping = $settings->getValue('context_mapping', []);
+      $context_mapping = $sub_form_state->getValue('context_mapping', []);
       $block->setContextMapping($context_mapping);
     }
-    // Update the original form values.
-    $form_state->setValue('settings', $settings->getValues());
 
     // Submit visibility condition settings.
     foreach ($form_state->getValue('visibility') as $condition_id => $values) {
       // Allow the condition to submit the form.
       $condition = $form_state->get(['conditions', $condition_id]);
-      $condition_values = (new FormState())
-        ->setValues($values);
-      $condition->submitConfigurationForm($form, $condition_values);
+      $condition->submitConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form_state));
+
       if ($condition instanceof ContextAwarePluginInterface) {
         $context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : [];
         $condition->setContextMapping($context_mapping);
       }
-      // Update the original form values.
       $condition_configuration = $condition->getConfiguration();
-      $form_state->setValue(['visibility', $condition_id], $condition_configuration);
       // Update the visibility conditions on the block.
       $entity->getVisibilityConditions()->addInstanceId($condition_id, $condition_configuration);
     }
diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php
index 6b55667..aba22cf 100644
--- a/core/modules/block/src/Tests/BlockUiTest.php
+++ b/core/modules/block/src/Tests/BlockUiTest.php
@@ -293,4 +293,18 @@ public function testBlockPlacementIndicator() {
     $this->assertUrl('admin/structure/block/list/classy');
   }
 
+  /**
+   * Tests if validation errors are passed from the 'settings' subform to the
+   * block configuration form.
+   */
+  public function testBlockValidateErrors() {
+    $this->drupalPostForm('admin/structure/block/add/test_settings_validation/classy', ['settings[digits]' => 'abc'], t('Save block'));
+    $arguments = [':message' => 'Only digits are allowed'];
+    $pattern = '//div[contains(@class,"messages messages--error")]/div[contains(text()[2],:message)]';
+    $elements = $this->xpath($pattern, $arguments);
+    $error_class_pattern = '//div[contains(@class,"form-item-settings-digits")]/input[contains(@class,"error")]';
+    $error_class = $this->xpath($error_class_pattern);
+    $this->assertTrue(!empty($elements) && !empty($error_class));
+  }
+
 }
diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestSettingsValidationBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestSettingsValidationBlock.php
new file mode 100644
index 0000000..4c9d2e4
--- /dev/null
+++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestSettingsValidationBlock.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\block_test\Plugin\Block\TestSettingsValidationBlock.
+ */
+
+namespace Drupal\block_test\Plugin\Block;
+
+use Drupal\Core\Block\BlockBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Provides a test settings validation block.
+ *
+ * @Block(
+ *  id = "test_settings_validation",
+ *  admin_label = @Translation("Test settings validation block"),
+ * )
+ */
+class TestSettingsValidationBlock extends BlockBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function blockForm($form, FormStateInterface $form_state) {
+    return ['digits' => ['#type' => 'textfield']] + $form;
+  }
+
+  public function blockValidate($form, FormStateInterface $form_state) {
+    if (!ctype_digit($form_state->getValue('digits'))) {
+      $form_state->setErrorByName('digits', $this->t('Only digits are allowed'));
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function build() {
+    return ['#markup' => 'foo'];
+  }
+
+}
diff --git a/core/modules/image/src/Form/ImageEffectFormBase.php b/core/modules/image/src/Form/ImageEffectFormBase.php
index 66edd95..24542c4 100644
--- a/core/modules/image/src/Form/ImageEffectFormBase.php
+++ b/core/modules/image/src/Form/ImageEffectFormBase.php
@@ -8,8 +8,8 @@
 namespace Drupal\image\Form;
 
 use Drupal\Core\Form\FormBase;
-use Drupal\Core\Form\FormState;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Form\SubformState;
 use Drupal\image\ConfigurableImageEffectInterface;
 use Drupal\image\ImageStyleInterface;
 use Drupal\Component\Plugin\Exception\PluginNotFoundException;
@@ -30,7 +30,7 @@
   /**
    * The image effect.
    *
-   * @var \Drupal\image\ImageEffectInterface
+   * @var \Drupal\image\ImageEffectInterface|\Drupal\image\ConfigurableImageEffectInterface
    */
   protected $imageEffect;
 
@@ -78,7 +78,9 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl
       '#value' => $this->imageEffect->getPluginId(),
     );
 
-    $form['data'] = $this->imageEffect->buildConfigurationForm(array(), $form_state);
+    $form['data'] = [];
+    $subform_state = SubformState::createForSubform($form['data'], $form_state);
+    $form['data'] = $this->imageEffect->buildConfigurationForm($form['data'], $subform_state);
     $form['data']['#tree'] = TRUE;
 
     // Check the URL for a weight, then the image effect, otherwise use default.
@@ -107,10 +109,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl
   public function validateForm(array &$form, FormStateInterface $form_state) {
     // The image effect configuration is stored in the 'data' key in the form,
     // pass that through for validation.
-    $effect_data = (new FormState())->setValues($form_state->getValue('data'));
-    $this->imageEffect->validateConfigurationForm($form, $effect_data);
-    // Update the original form values.
-    $form_state->setValue('data', $effect_data->getValues());
+    $this->imageEffect->validateConfigurationForm($form['data'], SubformState::createForSubform($form['data'], $form_state));
   }
 
   /**
@@ -121,10 +120,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
 
     // The image effect configuration is stored in the 'data' key in the form,
     // pass that through for submission.
-    $effect_data = (new FormState())->setValues($form_state->getValue('data'));
-    $this->imageEffect->submitConfigurationForm($form, $effect_data);
-    // Update the original form values.
-    $form_state->setValue('data', $effect_data->getValues());
+    $this->imageEffect->submitConfigurationForm($form['data'], SubformState::createForSubform($form['data'], $form_state));
 
     $this->imageEffect->setWeight($form_state->getValue('weight'));
     if (!$this->imageEffect->getUuid()) {
diff --git a/core/modules/image/src/Tests/ImageEffectsTest.php b/core/modules/image/src/Tests/ImageEffectsTest.php
index fd29537..3fc133d 100644
--- a/core/modules/image/src/Tests/ImageEffectsTest.php
+++ b/core/modules/image/src/Tests/ImageEffectsTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\image\Tests;
 
+use Drupal\image\Entity\ImageStyle;
 use Drupal\system\Tests\Image\ToolkitTestBase;
 
 /**
@@ -168,6 +169,27 @@ function testImageEffectsCaching() {
   }
 
   /**
+   * Tests if validation errors are passed from effect object validation to
+   * effect form.
+   */
+  public function testEffectFormValidationErrors() {
+    $account = $this->drupalCreateUser(['administer image styles']);
+    $this->drupalLogin($account);
+    /** @var \Drupal\image\ImageStyleInterface $style */
+    $style = ImageStyle::load('thumbnail');
+    // Image Scale is the only effect shipped with 'thumbnail', by default.
+    $uuids = $style->getEffects()->getInstanceIds();
+    $uuid = key($uuids);
+
+    // We are posting the form with both, width and height, empty.
+    $edit = ['data[width]' => '', 'data[height]' => ''];
+    $path = 'admin/config/media/image-styles/manage/thumbnail/effects/' . $uuid;
+    $this->drupalPostForm($path, $edit, t('Update effect'));
+    // Check that the error message has been displayed.
+    $this->assertText(t('Width and height can not both be blank.'));
+  }
+
+  /**
    * Asserts the effect processing of an image effect plugin.
    *
    * @param string $effect_name
diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php
new file mode 100644
index 0000000..ff69778
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Form/FormStateDecoratorBaseTest.php
@@ -0,0 +1,1230 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Form\FormStateDecoratorBaseTest.
+ */
+
+namespace Drupal\Tests\Core\Form;
+
+use Drupal\Core\Form\FormInterface;
+use Drupal\Core\Form\FormStateDecoratorBase;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Form\FormStateValuesTrait;
+use Drupal\Core\Url;
+use Drupal\Tests\UnitTestCase;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Form\FormStateDecoratorBase
+ *
+ * @group Form
+ */
+class FormStateDecoratorBaseTest extends UnitTestCase {
+
+  /**
+   * The decorated form state.
+   *
+   * @var \Drupal\Core\Form\FormStateInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $decoratedFormState;
+
+  /**
+   * The subject under test.
+   *
+   * @var \Drupal\Core\Form\FormStateDecoratorBase
+   */
+  protected $sut;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+
+    $this->decoratedFormState = $this->getMock(FormStateInterface::class);
+
+    $this->sut = $this->getMockForAbstractClass(FormStateDecoratorBase::class);
+    $decorated_form_state_property = new \ReflectionProperty($this->sut, 'decoratedFormState');
+    $decorated_form_state_property->setAccessible(TRUE);
+    $decorated_form_state_property->setValue($this->sut, $this->decoratedFormState);
+  }
+
+  /**
+   * @covers ::setFormState
+   */
+  public function testSetFormState() {
+    $form_state_additions = [
+      'foo' => 'bar',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setFormState')
+      ->with($form_state_additions);
+
+    $this->assertSame($this->sut, $this->sut->setFormState($form_state_additions));
+  }
+
+  /**
+   * @covers ::setAlwaysProcess
+   * @covers ::getAlwaysProcess
+   *
+   * @dataProvider providerGetAlwaysProcess
+   *
+   * @param bool $always_process
+   */
+  public function testGetAlwaysProcess($always_process) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setAlwaysProcess')
+      ->with($always_process);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getAlwaysProcess')
+      ->willReturn($always_process);
+
+    $this->assertSame($this->sut, $this->sut->setAlwaysProcess($always_process));
+    $this->assertSame($always_process, $this->sut->getAlwaysProcess());
+  }
+
+  /**
+   * Provides data to self::testGetAlwaysProcess().
+   */
+  public function providerGetAlwaysProcess() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setButtons
+   * @covers ::getButtons
+   */
+  public function testGetButtons() {
+    $buttons = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setButtons')
+      ->with($buttons);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getButtons')
+      ->willReturn($buttons);
+
+    $this->assertSame($this->sut, $this->sut->setButtons($buttons));
+    $this->assertSame($buttons, $this->sut->getButtons());
+  }
+
+  /**
+   * @covers ::setCached
+   * @covers ::isCached
+   *
+   * @dataProvider providerIsCached
+   *
+   * @param bool $cache
+   */
+  public function testIsCached($cache) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setCached')
+      ->with($cache);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isCached')
+      ->willReturn($cache);
+
+    $this->assertSame($this->sut, $this->sut->setCached($cache));
+    $this->assertSame($cache, $this->sut->isCached());
+  }
+
+  /**
+   * Provides data to self::testIsCached().
+   */
+  public function providerIsCached() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setCached
+   *
+   * @expectedException \LogicException
+   */
+  public function testIsCachedWithLogicException() {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setCached')
+      ->willThrowException(new \LogicException());
+
+    $this->assertSame($this->sut, $this->sut->setCached());
+  }
+
+  /**
+   * @covers ::disableCache
+   */
+  public function testDisableCache() {
+    $this->decoratedFormState->expects($this->once())
+      ->method('disableCache');
+
+    $this->assertSame($this->sut, $this->sut->disableCache());
+  }
+
+  /**
+   * @covers ::setExecuted
+   */
+  public function testSetExecuted() {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setExecuted');
+
+    $this->assertSame($this->sut, $this->sut->setExecuted());
+  }
+
+  /**
+   * @covers ::isExecuted
+   *
+   * @dataProvider providerIsExecuted
+   *
+   * @param bool $executed
+   */
+  public function testIsExecuted($executed) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('isExecuted')
+      ->willReturn($executed);
+
+    $this->assertSame($executed, $this->sut->isExecuted());
+  }
+
+  /**
+   * Provides data to self::testIsExecuted().
+   */
+  public function providerIsExecuted() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setGroups
+   * @covers ::getGroups
+   */
+  public function testGetGroups() {
+    $groups = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setGroups')
+      ->with($groups);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getGroups')
+      ->willReturn($groups);
+
+    $this->assertSame($this->sut, $this->sut->setGroups($groups));
+    $this->assertSame($groups, $this->sut->getGroups());
+  }
+
+  /**
+   * @covers ::setHasFileElement
+   * @covers ::hasFileElement
+   *
+   * @dataProvider providerHasFileElement
+   *
+   * @param bool $has_file_element
+   */
+  public function testHasFileElement($has_file_element) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setHasFileElement')
+      ->with($has_file_element);
+    $this->decoratedFormState->expects($this->once())
+      ->method('hasFileElement')
+      ->willReturn($has_file_element);
+
+    $this->assertSame($this->sut, $this->sut->setHasFileElement($has_file_element));
+    $this->assertSame($has_file_element, $this->sut->hasFileElement());
+  }
+
+  /**
+   * Provides data to self::testHasFileElement().
+   */
+  public function providerHasFileElement() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setLimitValidationErrors
+   * @covers ::getLimitValidationErrors
+   *
+   * @dataProvider providerHasFileElement
+   *
+   * @param bool $limit_validation_errors
+   */
+  public function testGetLimitValidationErrors($limit_validation_errors) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setLimitValidationErrors')
+      ->with($limit_validation_errors);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getLimitValidationErrors')
+      ->willReturn($limit_validation_errors);
+
+    $this->assertSame($this->sut, $this->sut->setLimitValidationErrors($limit_validation_errors));
+    $this->assertSame($limit_validation_errors, $this->sut->getLimitValidationErrors());
+  }
+
+  /**
+   * Provides data to self::testGetLimitValidationErrors().
+   */
+  public function providerGetLimitValidationErrors() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setMethod
+   *
+   * @dataProvider providerSetMethod
+   *
+   * @param bool $method
+   */
+  public function testSetMethod($method) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setMethod')
+      ->with($method);
+
+    $this->assertSame($this->sut, $this->sut->setMethod($method));
+  }
+
+  /**
+   * Provides data to self::testSetMethod().
+   */
+  public function providerSetMethod() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::isMethodType
+   *
+   * @dataProvider providerIsMethodType
+   *
+   * @param bool $expected_return_value
+   * @param string $method_type
+   *   Either "GET" or "POST".
+   */
+  public function testIsMethodType($expected_return_value, $method_type) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('isMethodType')
+      ->with($method_type)
+      ->willReturn($expected_return_value);
+
+    $this->assertSame($expected_return_value, $this->sut->isMethodType($method_type));
+  }
+
+  /**
+   * Provides data to self::testIsMethodType().
+   */
+  public function providerIsMethodType() {
+    return [
+      [TRUE, 'GET'],
+      [TRUE, 'POST'],
+      [FALSE, 'GET'],
+      [FALSE, 'POST'],
+    ];
+  }
+
+  /**
+   * @covers ::setMethod
+   *
+   * @dataProvider providerSetMethod
+   *
+   * @param bool $method
+   */
+  public function testSetRequestMethod($method) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setRequestMethod')
+      ->with($method);
+
+    $this->assertSame($this->sut, $this->sut->setRequestMethod($method));
+  }
+
+  /**
+   * Provides data to self::testSetMethod().
+   */
+  public function providerSetRequestMethod() {
+    return [
+      ['GET'],
+      ['POST'],
+    ];
+  }
+
+  /**
+   * @covers ::setValidationEnforced
+   * @covers ::isValidationEnforced
+   *
+   * @dataProvider providerIsValidationEnforced
+   *
+   * @param bool $must_validate
+   */
+  public function testIsValidationEnforced($must_validate) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setValidationEnforced')
+      ->with($must_validate);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isValidationEnforced')
+      ->willReturn($must_validate);
+
+    $this->assertSame($this->sut, $this->sut->setValidationEnforced($must_validate));
+    $this->assertSame($must_validate, $this->sut->isValidationEnforced());
+  }
+
+  /**
+   * Provides data to self::testIsValidationEnforced().
+   */
+  public function providerIsValidationEnforced() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::disableRedirect
+   * @covers ::isRedirectDisabled
+   *
+   * @dataProvider providerIsRedirectDisabled
+   *
+   * @param bool $no_redirect
+   */
+  public function testIsRedirectDisabled($no_redirect) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('disableRedirect')
+      ->with($no_redirect);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isRedirectDisabled')
+      ->willReturn($no_redirect);
+
+    $this->assertSame($this->sut, $this->sut->disableRedirect($no_redirect));
+    $this->assertSame($no_redirect, $this->sut->isRedirectDisabled());
+  }
+
+  /**
+   * Provides data to self::testIsRedirectDisabled().
+   */
+  public function providerIsRedirectDisabled() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setProcessInput
+   * @covers ::isProcessingInput
+   *
+   * @dataProvider providerIsProcessingInput
+   *
+   * @param bool $process_input
+   */
+  public function testIsProcessingInput($process_input) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setProcessInput')
+      ->with($process_input);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isProcessingInput')
+      ->willReturn($process_input);
+
+    $this->assertSame($this->sut, $this->sut->setProcessInput($process_input));
+    $this->assertSame($process_input, $this->sut->isProcessingInput());
+  }
+
+  /**
+   * Provides data to self::testIsProcessingInput().
+   */
+  public function providerIsProcessingInput() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setProgrammed
+   * @covers ::isProgrammed
+   *
+   * @dataProvider providerIsProgrammed
+   *
+   * @param bool $programmed
+   */
+  public function testIsProgrammed($programmed) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setProgrammed')
+      ->with($programmed);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isProgrammed')
+      ->willReturn($programmed);
+
+    $this->assertSame($this->sut, $this->sut->setProgrammed($programmed));
+    $this->assertSame($programmed, $this->sut->isProgrammed());
+  }
+
+  /**
+   * Provides data to self::testIsProgrammed().
+   */
+  public function providerIsProgrammed() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setProgrammedBypassAccessCheck
+   * @covers ::isBypassingProgrammedAccessChecks
+   *
+   * @dataProvider providerIsBypassingProgrammedAccessChecks
+   *
+   * @param bool $programmed_bypass_access_check
+   */
+  public function testIsBypassingProgrammedAccessChecks($programmed_bypass_access_check) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setProgrammedBypassAccessCheck')
+      ->with($programmed_bypass_access_check);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isBypassingProgrammedAccessChecks')
+      ->willReturn($programmed_bypass_access_check);
+
+    $this->assertSame($this->sut, $this->sut->setProgrammedBypassAccessCheck($programmed_bypass_access_check));
+    $this->assertSame($programmed_bypass_access_check, $this->sut->isBypassingProgrammedAccessChecks());
+  }
+
+  /**
+   * Provides data to self::testIsBypassingProgrammedAccessChecks().
+   */
+  public function providerIsBypassingProgrammedAccessChecks() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setRebuildInfo
+   * @covers ::getRebuildInfo
+   * @covers ::addRebuildInfo
+   */
+  public function testGetRebuildInfo() {
+    $rebuild_info = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setRebuildInfo')
+      ->with($rebuild_info);
+    $this->decoratedFormState->expects($this->once())
+      ->method('addRebuildInfo')
+      ->with('FOO', $rebuild_info['FOO']);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getRebuildInfo')
+      ->willReturn($rebuild_info);
+
+    $this->assertSame($this->sut, $this->sut->setRebuildInfo($rebuild_info));
+    $this->assertSame($this->sut, $this->sut->addRebuildInfo('FOO', $rebuild_info['FOO']));
+    $this->assertSame($rebuild_info, $this->sut->getRebuildInfo());
+  }
+
+  /**
+   * @covers ::setStorage
+   * @covers ::getStorage
+   */
+  public function testGetStorage() {
+    $storage = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setStorage')
+      ->with($storage);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getStorage')
+      ->willReturn($storage);
+
+    $this->assertSame($this->sut, $this->sut->setStorage($storage));
+    $this->assertSame($storage, $this->sut->getStorage());
+  }
+
+  /**
+   * @covers ::setSubmitHandlers
+   * @covers ::getSubmitHandlers
+   */
+  public function testGetSubmitHandlers() {
+    $submit_handlers = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setSubmitHandlers')
+      ->with($submit_handlers);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getSubmitHandlers')
+      ->willReturn($submit_handlers);
+
+    $this->assertSame($this->sut, $this->sut->setSubmitHandlers($submit_handlers));
+    $this->assertSame($submit_handlers, $this->sut->getSubmitHandlers());
+  }
+
+  /**
+   * @covers ::setSubmitted
+   */
+  public function testSetSubmitted() {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setSubmitted');
+
+    $this->assertSame($this->sut, $this->sut->setSubmitted());
+  }
+
+  /**
+   * @covers ::isSubmitted
+   *
+   * @dataProvider providerIsSubmitted
+   *
+   * @param bool $submitted
+   */
+  public function testIsSubmitted($submitted) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('isSubmitted')
+      ->willReturn($submitted);
+
+    $this->assertSame($submitted, $this->sut->isSubmitted());
+  }
+
+  /**
+   * Provides data to self::testIsSubmitted().
+   */
+  public function providerIsSubmitted() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setTemporary
+   * @covers ::getTemporary
+   */
+  public function testGetTemporary() {
+    $temporary = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setTemporary')
+      ->with($temporary);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getTemporary')
+      ->willReturn($temporary);
+
+    $this->assertSame($this->sut, $this->sut->setTemporary($temporary));
+    $this->assertSame($temporary, $this->sut->getTemporary());
+  }
+
+  /**
+   * @covers ::setTemporaryValue
+   * @covers ::getTemporaryValue
+   * @covers ::hasTemporaryValue
+   *
+   * @dataProvider providerGetTemporaryValue
+   *
+   * @param bool $exists
+   * @param string $key
+   * @param mixed $value
+   */
+  public function testGetTemporaryValue($exists, $key, $value = NULL) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setTemporaryValue')
+      ->with($key, $value);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getTemporaryValue')
+      ->with($key)
+      ->willReturn($value);
+    $this->decoratedFormState->expects($this->once())
+      ->method('hasTemporaryValue')
+      ->with($key)
+      ->willReturn($exists);
+
+    $this->assertSame($this->sut, $this->sut->setTemporaryValue($key, $value));
+    $this->assertSame($value, $this->sut->getTemporaryValue($key));
+    $this->assertSame($exists, $this->sut->hasTemporaryValue($key));
+  }
+
+  /**
+   * Provides data to self::testGetTemporaryValue().
+   */
+  public function providerGetTemporaryValue() {
+    return [
+      // Existing values.
+      [TRUE, 'FOO', 'BAR'],
+      [TRUE, 'FOO', NULL],
+      // Non-existent values.
+      [FALSE, 'BAZ'],
+      [FALSE, 'QUX'],
+    ];
+  }
+
+  /**
+   * @covers ::setTriggeringElement
+   * @covers ::getTriggeringElement
+   */
+  public function testSetTriggeringElement() {
+    $triggering_element = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setTriggeringElement')
+      ->with($triggering_element);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getTriggeringElement')
+      ->willReturn($triggering_element);
+
+    $this->assertSame($this->sut, $this->sut->setTriggeringElement($triggering_element));
+    $this->assertSame($triggering_element, $this->sut->getTriggeringElement());
+  }
+
+  /**
+   * @covers ::setValidateHandlers
+   * @covers ::getValidateHandlers
+   */
+  public function testGetValidateHandlers() {
+    $validate_handlers = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setValidateHandlers')
+      ->with($validate_handlers);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getValidateHandlers')
+      ->willReturn($validate_handlers);
+
+    $this->assertSame($this->sut, $this->sut->setValidateHandlers($validate_handlers));
+    $this->assertSame($validate_handlers, $this->sut->getValidateHandlers());
+  }
+
+  /**
+   * @covers ::setValidationComplete
+   * @covers ::isValidationComplete
+   *
+   * @dataProvider providerIsValidationComplete
+   *
+   * @param bool $complete
+   */
+  public function testIsValidationComplete($complete) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setValidationComplete')
+      ->with($complete);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isValidationComplete')
+      ->willReturn($complete);
+
+    $this->assertSame($this->sut, $this->sut->setValidationComplete($complete));
+    $this->assertSame($complete, $this->sut->isValidationComplete());
+  }
+
+  /**
+   * Provides data to self::testIsValidationComplete().
+   */
+  public function providerIsValidationComplete() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::loadInclude
+   * @covers ::isValidationComplete
+   *
+   * @dataProvider providerLoadInclude
+   *
+   * @param string|false $expected
+   * @param string $module
+   * @param string $type
+   * @param string|null $name
+   */
+  public function testLoadInclude($expected, $module, $type, $name) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('loadInclude')
+      ->with($module, $type, $name)
+      ->willReturn($expected);
+
+    $this->assertSame($expected, $this->sut->loadInclude($module, $type, $name));
+  }
+
+  /**
+   * Provides data to self::testLoadInclude().
+   */
+  public function providerLoadInclude() {
+    return [
+      // Existing files.
+      [__FILE__, 'foo', 'inc', 'foo'],
+      [__FILE__, 'foo', 'inc', 'foo.admin'],
+      [__FILE__, 'bar', 'inc', 'bar'],
+      // Non-existent files.
+      [FALSE, 'foo', 'php', 'foo'],
+      [FALSE, 'bar', 'php', 'foo'],
+    ];
+  }
+
+  /**
+   * @covers ::getCacheableArray
+   */
+  public function testGetCacheableArray() {
+    $cacheable_array = [
+      'foo' => 'bar',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('getCacheableArray')
+      ->willReturn($cacheable_array);
+
+    $this->assertSame($cacheable_array, $this->sut->getCacheableArray());
+  }
+
+  /**
+   * @covers ::setCompleteForm
+   * @covers ::getCompleteForm
+   */
+  public function testGetCompleteForm() {
+    $complete_form = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setCompleteForm')
+      ->with($complete_form);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getCompleteForm')
+      ->willReturn($complete_form);
+
+    $this->assertSame($this->sut, $this->sut->setCompleteForm($complete_form));
+    $this->assertSame($complete_form, $this->sut->getCompleteForm());
+  }
+
+  /**
+   * @covers ::set
+   * @covers ::get
+   * @covers ::has
+   *
+   * @dataProvider providerGet
+   *
+   * @param bool $exists
+   * @param string $key
+   * @param mixed $value
+   */
+  public function testGet($exists, $key, $value = NULL) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('set')
+      ->with($key, $value);
+    $this->decoratedFormState->expects($this->once())
+      ->method('get')
+      ->with($key)
+      ->willReturn($value);
+    $this->decoratedFormState->expects($this->once())
+      ->method('has')
+      ->with($key)
+      ->willReturn($exists);
+
+    $this->assertSame($this->sut, $this->sut->set($key, $value));
+    $this->assertSame($value, $this->sut->get($key));
+    $this->assertSame($exists, $this->sut->has($key));
+  }
+
+  /**
+   * Provides data to self::testGet().
+   */
+  public function providerGet() {
+    return [
+      // Existing values.
+      [TRUE, 'FOO', 'BAR'],
+      [TRUE, 'FOO', NULL],
+      // Non-existent values.
+      [FALSE, 'BAZ'],
+      [FALSE, 'QUX'],
+    ];
+  }
+
+  /**
+   * @covers ::setBuildInfo
+   * @covers ::getBuildInfo
+   * @covers ::addBuildInfo
+   */
+  public function testGetBuildInfo() {
+    $build_info = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setBuildInfo')
+      ->with($build_info);
+    $this->decoratedFormState->expects($this->once())
+      ->method('addBuildInfo')
+      ->with('FOO', $build_info['FOO']);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getBuildInfo')
+      ->willReturn($build_info);
+
+    $this->assertSame($this->sut, $this->sut->setBuildInfo($build_info));
+    $this->assertSame($this->sut, $this->sut->addBuildInfo('FOO', $build_info['FOO']));
+    $this->assertSame($build_info, $this->sut->getBuildInfo());
+  }
+
+  /**
+   * @covers ::setUserInput
+   * @covers ::getUserInput
+   */
+  public function testSetUserInput() {
+    $user_input = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setUserInput')
+      ->with($user_input);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getUserInput')
+      ->willReturn($user_input);
+
+    $this->assertSame($this->sut, $this->sut->setUserInput($user_input));
+    $this->assertSame($user_input, $this->sut->getUserInput());
+  }
+
+  /**
+   * @covers ::getValues
+   */
+  public function testGetValues() {
+    $values = [
+      'FOO' => 'BAR',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('getValues')
+      ->willReturn($values);
+
+    $this->assertSame($values, $this->sut->getValues());
+  }
+
+  /**
+   * @covers ::setResponse
+   * @covers ::getResponse
+   */
+  public function testGetResponse() {
+    $response = $this->getMock(Response::class);
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setResponse')
+      ->with($response);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getResponse')
+      ->willReturn($response);
+
+    $this->assertSame($this->sut, $this->sut->setResponse($response));
+    $this->assertSame($response, $this->sut->getResponse());
+  }
+
+  /**
+   * @covers ::setRedirect
+   */
+  public function testSetRedirect() {
+    $route_name = 'foo';
+    $route_parameters = [
+      'bar' => 'baz'
+    ];
+    $options = [
+      'qux' => 'foo',
+    ];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setRedirect')
+      ->with($route_name, $route_parameters, $options);
+
+    $this->assertSame($this->sut, $this->sut->setRedirect($route_name, $route_parameters, $options));
+  }
+
+  /**
+   * @covers ::setRedirectUrl
+   */
+  public function testSetRedirectUrl() {
+    $url = new Url('foo');
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setRedirectUrl')
+      ->with($url);
+
+    $this->assertSame($this->sut, $this->sut->setRedirectUrl($url));
+  }
+
+  /**
+   * @covers ::getRedirect
+   *
+   * @dataProvider providerGetRedirect
+   *
+   * @param bool $expected
+   */
+  public function testGetRedirect($expected) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('getRedirect')
+      ->willReturn($expected);
+
+    $this->assertSame($expected, $this->sut->getRedirect());
+  }
+
+  /**
+   * Provides data to self::testGetRedirect().
+   */
+  public function providerGetRedirect() {
+    return [
+      [NULL],
+      [FALSE],
+      [new Url('foo')],
+      [new RedirectResponse('http://example.com')],
+    ];
+  }
+
+  /**
+   * @covers ::setErrorByName
+   */
+  public function testSetErrorByName() {
+    $name = 'foo';
+    $message = 'bar';
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setErrorByName')
+      ->with($name, $message);
+
+    $this->assertSame($this->sut, $this->sut->setErrorByName($name, $message));
+  }
+
+  /**
+   * @covers ::setError
+   */
+  public function testSetError() {
+    $element = [
+      '#foo' => 'bar',
+    ];
+    $message = 'bar';
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setError')
+      ->with($element, $message);
+
+    $this->assertSame($this->sut, $this->sut->setError($element, $message));
+  }
+
+  /**
+   * @covers ::clearErrors
+   */
+  public function testClearErrors() {
+    $this->decoratedFormState->expects($this->once())
+      ->method('clearErrors');
+
+    $this->sut->clearErrors();
+  }
+
+  /**
+   * @covers ::getError
+   */
+  public function testGetError() {
+    $element = [
+      '#foo' => 'bar',
+    ];
+    $message = 'bar';
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('getError')
+      ->with($element)
+      ->willReturn($message);
+
+    $this->assertSame($message, $this->sut->getError($element));
+  }
+
+  /**
+   * @covers ::getErrors
+   */
+  public function testGetErrors() {
+    $errors = [
+      'foo' => 'bar',
+    ];
+    $this->decoratedFormState->expects($this->once())
+      ->method('getErrors')
+      ->willReturn($errors);
+
+    $this->assertSame($errors, $this->sut->getErrors());
+  }
+
+  /**
+   * @covers ::setRebuild
+   * @covers ::isRebuilding
+   *
+   * @dataProvider providerIsRebuilding
+   *
+   * @param bool $rebuild
+   */
+  public function testIsRebuilding($rebuild) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setRebuild')
+      ->with($rebuild);
+    $this->decoratedFormState->expects($this->once())
+      ->method('isRebuilding')
+      ->willReturn($rebuild);
+
+    $this->assertSame($this->sut, $this->sut->setRebuild($rebuild));
+    $this->assertSame($rebuild, $this->sut->isRebuilding());
+  }
+
+  /**
+   * Provides data to self::testIsRebuilding().
+   */
+  public function providerIsRebuilding() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::setInvalidToken
+   * @covers ::hasInvalidToken
+   *
+   * @dataProvider providerHasInvalidToken
+   *
+   * @param bool $expected
+   */
+  public function testHasInvalidToken($expected) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('setInvalidToken')
+      ->with($expected);
+    $this->decoratedFormState->expects($this->once())
+      ->method('hasInvalidToken')
+      ->willReturn($expected);
+
+    $this->assertSame($this->sut, $this->sut->setInvalidToken($expected));
+    $this->assertSame($expected, $this->sut->hasInvalidToken());
+  }
+
+  /**
+   * Provides data to self::testHasInvalidToken().
+   */
+  public function providerHasInvalidToken() {
+    return [
+      [TRUE],
+      [FALSE],
+    ];
+  }
+
+  /**
+   * @covers ::prepareCallback
+   *
+   * @dataProvider providerPrepareCallback
+   *
+   * @param string|callable $unprepared_callback
+   * @param callable $prepared_callback
+   */
+  public function testPrepareCallback($unprepared_callback, callable $prepared_callback) {
+    $this->decoratedFormState->expects($this->once())
+      ->method('prepareCallback')
+      ->with($unprepared_callback)
+      ->willReturn($prepared_callback);
+
+    $this->assertSame($prepared_callback, $this->sut->prepareCallback($unprepared_callback));
+  }
+
+  /**
+   * Provides data to self::testPrepareCallback().
+   */
+  public function providerPrepareCallback() {
+    $function = 'sleep';
+    $shorthand_form_method = '::submit()';
+    $closure = function() {};
+    $static_method_string = __METHOD__;
+    $static_method_array = [__CLASS__, __FUNCTION__];
+    $object_method_array = [$this, __FUNCTION__];
+
+    return [
+      // A shorthand form method is generally expanded to become a method on an
+      // object.
+      [$shorthand_form_method, $object_method_array],
+      // Functions, closures, and static method calls generally remain the same.
+      [$function, $function],
+      [$closure, $closure],
+      [$static_method_string, $static_method_string],
+      [$static_method_array, $static_method_array],
+    ];
+  }
+
+  /**
+   * @covers ::setFormObject
+   * @covers ::getFormObject
+   */
+  public function testGetFormObject() {
+    $form = $this->getMock(FormInterface::class);
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setFormObject')
+      ->with($form);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getFormObject')
+      ->willReturn($form);
+
+    $this->assertSame($this->sut, $this->sut->setFormObject($form));
+    $this->assertSame($form, $this->sut->getFormObject());
+  }
+
+  /**
+   * @covers ::setCleanValueKeys
+   * @covers ::getCleanValueKeys
+   */
+  public function testGetCleanValueKeys() {
+    $keys = ['BAR'];
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('setCleanValueKeys')
+      ->with($keys);
+    $this->decoratedFormState->expects($this->once())
+      ->method('getCleanValueKeys')
+      ->willReturn($keys);
+
+    $this->assertSame($this->sut, $this->sut->setCleanValueKeys($keys));
+    $this->assertSame($keys, $this->sut->getCleanValueKeys());
+  }
+
+  /**
+   * @covers ::addCleanValueKey
+   */
+  public function testAddCleanValueKey() {
+    $key = 'BAR';
+
+    $this->decoratedFormState->expects($this->once())
+      ->method('addCleanValueKey')
+      ->with($key);
+
+    $this->assertSame($this->sut, $this->sut->addCleanValueKey($key));
+  }
+
+  /**
+   * @covers ::cleanValues
+   */
+  public function testCleanValues() {
+    $this->decoratedFormState->expects($this->once())
+      ->method('cleanValues');
+
+    $this->assertSame($this->sut, $this->sut->cleanValues());
+  }
+
+}
diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
index 24904e3..51b1a91 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
@@ -143,75 +143,6 @@ public function testFormErrorsDuringSubmission() {
   }
 
   /**
-   * Tests that setting the value for an element adds to the values.
-   *
-   * @covers ::setValueForElement
-   */
-  public function testSetValueForElement() {
-    $element = array(
-      '#parents' => array(
-        'foo',
-        'bar',
-      ),
-    );
-    $value = $this->randomMachineName();
-
-    $form_state = new FormState();
-    $form_state->setValueForElement($element, $value);
-    $expected = array(
-      'foo' => array(
-        'bar' => $value,
-      ),
-    );
-    $this->assertSame($expected, $form_state->getValues());
-  }
-
-  /**
-   * @covers ::getValue
-   *
-   * @dataProvider providerTestGetValue
-   */
-  public function testGetValue($key, $expected, $default = NULL) {
-    $form_state = (new FormState())->setValues([
-      'foo' => 'one',
-      'bar' => array(
-        'baz' => 'two',
-      ),
-    ]);
-    $this->assertSame($expected, $form_state->getValue($key, $default));
-  }
-
-  public function providerTestGetValue() {
-    $data = array();
-    $data[] = array(
-      'foo', 'one',
-    );
-    $data[] = array(
-      array('bar', 'baz'), 'two',
-    );
-    $data[] = array(
-      array('foo', 'bar', 'baz'), NULL,
-    );
-    $data[] = array(
-      'baz', 'baz', 'baz',
-    );
-    return $data;
-  }
-
-  /**
-   * @covers ::setValue
-   *
-   * @dataProvider providerTestSetValue
-   */
-  public function testSetValue($key, $value, $expected) {
-    $form_state = (new FormState())->setValues([
-      'bar' => 'wrong',
-    ]);
-    $form_state->setValue($key, $value);
-    $this->assertSame($expected, $form_state->getValues());
-  }
-
-  /**
    * @covers ::prepareCallback
    */
   public function testPrepareCallbackValidMethod() {
@@ -243,102 +174,6 @@ public function testPrepareCallbackArray() {
     $this->assertEquals($callback, $processed_callback);
   }
 
-  public function providerTestSetValue() {
-    $data = array();
-    $data[] = array(
-      'foo', 'one', array('bar' => 'wrong', 'foo' => 'one'),
-    );
-    $data[] = array(
-      array('bar', 'baz'), 'two', array('bar' => array('baz' => 'two')),
-    );
-    $data[] = array(
-      array('foo', 'bar', 'baz'), NULL, array('bar' => 'wrong', 'foo' => array('bar' => array('baz' => NULL))),
-    );
-    return $data;
-  }
-
-  /**
-   * @covers ::hasValue
-   *
-   * @dataProvider providerTestHasValue
-   */
-  public function testHasValue($key, $expected) {
-    $form_state = (new FormState())->setValues([
-      'foo' => 'one',
-      'bar' => array(
-        'baz' => 'two',
-      ),
-      'true' => TRUE,
-      'false' => FALSE,
-      'null' => NULL,
-    ]);
-    $this->assertSame($expected, $form_state->hasValue($key));
-  }
-
-  public function providerTestHasValue() {
-    $data = array();
-    $data[] = array(
-      'foo', TRUE,
-    );
-    $data[] = array(
-      array('bar', 'baz'), TRUE,
-    );
-    $data[] = array(
-      array('foo', 'bar', 'baz'), FALSE,
-    );
-    $data[] = array(
-      'true', TRUE,
-    );
-    $data[] = array(
-      'false', TRUE,
-    );
-    $data[] = array(
-      'null', FALSE,
-    );
-    return $data;
-  }
-
-  /**
-   * @covers ::isValueEmpty
-   *
-   * @dataProvider providerTestIsValueEmpty
-   */
-  public function testIsValueEmpty($key, $expected) {
-    $form_state = (new FormState())->setValues([
-      'foo' => 'one',
-      'bar' => array(
-        'baz' => 'two',
-      ),
-      'true' => TRUE,
-      'false' => FALSE,
-      'null' => NULL,
-    ]);
-    $this->assertSame($expected, $form_state->isValueEmpty($key));
-  }
-
-  public function providerTestIsValueEmpty() {
-    $data = array();
-    $data[] = array(
-      'foo', FALSE,
-    );
-    $data[] = array(
-      array('bar', 'baz'), FALSE,
-    );
-    $data[] = array(
-      array('foo', 'bar', 'baz'), TRUE,
-    );
-    $data[] = array(
-      'true', FALSE,
-    );
-    $data[] = array(
-      'false', TRUE,
-    );
-    $data[] = array(
-      'null', TRUE,
-    );
-    return $data;
-  }
-
   /**
    * @covers ::loadInclude
    */
@@ -583,6 +418,20 @@ public function testCleanValues($form_state) {
     $form_state->setValue('value_to_keep', 'magic_ponies');
     $this->assertSame($form_state->cleanValues()->getValues(), ['value_to_keep' => 'magic_ponies']);
   }
+
+  /**
+   * @covers ::setValues
+   * @covers ::getValues
+   */
+  public function testGetValues() {
+    $values = [
+      'foo' => 'bar',
+    ];
+    $form_state = new FormState();
+    $form_state->setValues($values);
+    $this->assertSame($values, $form_state->getValues());
+  }
+
 }
 
 /**
diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateValuesTraitTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateValuesTraitTest.php
new file mode 100644
index 0000000..543ccf7
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Form/FormStateValuesTraitTest.php
@@ -0,0 +1,267 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Form\FormStateValuesTraitTest.
+ */
+
+namespace Drupal\Tests\Core\Form;
+
+use Drupal\Core\Form\FormStateValuesTrait;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Form\FormStateValuesTrait
+ *
+ * @group Form
+ */
+class FormStateValuesTraitTest extends UnitTestCase {
+
+  /**
+   * Tests that setting the value for an element adds to the values.
+   *
+   * @covers ::setValueForElement
+   */
+  public function testSetValueForElement() {
+    $element = [
+      '#parents' => [
+        'foo',
+        'bar',
+      ],
+    ];
+    $value = $this->randomMachineName();
+
+    $form_state = new FormStateValuesTraitStub();
+    $form_state->setValueForElement($element, $value);
+    $expected = [
+      'foo' => [
+        'bar' => $value,
+      ],
+    ];
+    $this->assertSame($expected, $form_state->getValues());
+  }
+
+  /**
+   * @covers ::getValue
+   *
+   * @dataProvider providerGetValue
+   */
+  public function testGetValue($key, $expected, $default = NULL) {
+    $form_state = (new FormStateValuesTraitStub())->setValues([
+      'foo' => 'one',
+      'bar' => [
+        'baz' => 'two',
+      ],
+    ]);
+    $this->assertSame($expected, $form_state->getValue($key, $default));
+  }
+
+  /**
+   * Provides data to self::testGetValue().
+   *
+   * @return array[]
+   *   Items are arrays of two items:
+   *   - The key for which to get the value (string)
+   *   - The expected value (mixed).
+   *   - The default value (mixed).
+   */
+  public function providerGetValue() {
+    $data = [];
+    $data[] = [
+      'foo', 'one',
+    ];
+    $data[] = [
+      ['bar', 'baz'], 'two',
+    ];
+    $data[] = [
+      ['foo', 'bar', 'baz'], NULL,
+    ];
+    $data[] = [
+      'baz', 'baz', 'baz',
+    ];
+    $data[] = [
+      NULL,
+      [
+        'foo' => 'one',
+        'bar' => [
+          'baz' => 'two',
+        ],
+      ],
+    ];
+    return $data;
+  }
+
+  /**
+   * @covers ::getValue
+   */
+  public function testGetValueModifyReturn() {
+    $initial_values = $values = [
+      'foo' => 'one',
+      'bar' => [
+        'baz' => 'two',
+      ],
+    ];
+    $form_state = (new FormStateValuesTraitStub())->setValues($values);
+
+    $value = &$form_state->getValue(NULL);
+    $this->assertSame($initial_values, $value);
+    $value = ['bing' => 'bang'];
+    $this->assertSame(['bing' => 'bang'], $form_state->getValues());
+    $this->assertSame('bang', $form_state->getValue('bing'));
+    $this->assertSame(['bing' => 'bang'], $form_state->getValue(NULL));
+  }
+
+  /**
+   * @covers ::setValue
+   *
+   * @dataProvider providerSetValue
+   */
+  public function testSetValue($key, $value, $expected) {
+    $form_state = (new FormStateValuesTraitStub())->setValues([
+      'bar' => 'wrong',
+    ]);
+    $form_state->setValue($key, $value);
+    $this->assertSame($expected, $form_state->getValues());
+  }
+
+  /**
+   * Provides data to self::testSetValue().
+   *
+   * @return array[]
+   *   Items are arrays of two items:
+   *   - The key for which to set a new value (string)
+   *   - The new value to set (mixed).
+   *   - The expected form state values after setting the new value (mixed[]).
+   */
+  public function providerSetValue() {
+    $data = [];
+    $data[] = [
+      'foo', 'one', ['bar' => 'wrong', 'foo' => 'one'],
+    ];
+    $data[] = [
+      ['bar', 'baz'], 'two', ['bar' => ['baz' => 'two']],
+    ];
+    $data[] = [
+      ['foo', 'bar', 'baz'], NULL, ['bar' => 'wrong', 'foo' => ['bar' => ['baz' => NULL]]],
+    ];
+    return $data;
+  }
+
+  /**
+   * @covers ::hasValue
+   *
+   * @dataProvider providerHasValue
+   */
+  public function testHasValue($key, $expected) {
+    $form_state = (new FormStateValuesTraitStub())->setValues([
+      'foo' => 'one',
+      'bar' => [
+        'baz' => 'two',
+      ],
+      'true' => TRUE,
+      'false' => FALSE,
+      'null' => NULL,
+    ]);
+    $this->assertSame($expected, $form_state->hasValue($key));
+  }
+
+  /**
+   * Provides data to self::testHasValue().
+   *
+   * @return array[]
+   *   Items are arrays of two items:
+   *   - The key to check for in the form state (string)
+   *   - Whether the form state has an item with that key (bool).
+   */
+  public function providerHasValue() {
+    $data = [];
+    $data[] = [
+      'foo', TRUE,
+    ];
+    $data[] = [
+      ['bar', 'baz'], TRUE,
+    ];
+    $data[] = [
+      ['foo', 'bar', 'baz'], FALSE,
+    ];
+    $data[] = [
+      'true', TRUE,
+    ];
+    $data[] = [
+      'false', TRUE,
+    ];
+    $data[] = [
+      'null', FALSE,
+    ];
+    return $data;
+  }
+
+  /**
+   * @covers ::isValueEmpty
+   *
+   * @dataProvider providerIsValueEmpty
+   */
+  public function testIsValueEmpty($key, $expected) {
+    $form_state = (new FormStateValuesTraitStub())->setValues([
+      'foo' => 'one',
+      'bar' => [
+        'baz' => 'two',
+      ],
+      'true' => TRUE,
+      'false' => FALSE,
+      'null' => NULL,
+    ]);
+    $this->assertSame($expected, $form_state->isValueEmpty($key));
+  }
+
+  /**
+   * Provides data to self::testIsValueEmpty().
+   *
+   * @return array[]
+   *   Items are arrays of two items:
+   *   - The key to check for in the form state (string)
+   *   - Whether the value is empty or not (bool).
+   */
+  public function providerIsValueEmpty() {
+    $data = [];
+    $data[] = [
+      'foo', FALSE,
+    ];
+    $data[] = [
+      ['bar', 'baz'], FALSE,
+    ];
+    $data[] = [
+      ['foo', 'bar', 'baz'], TRUE,
+    ];
+    $data[] = [
+      'true', FALSE,
+    ];
+    $data[] = [
+      'false', TRUE,
+    ];
+    $data[] = [
+      'null', TRUE,
+    ];
+    return $data;
+  }
+
+}
+
+class FormStateValuesTraitStub {
+
+  use FormStateValuesTrait;
+
+  /**
+   * The submitted form values.
+   *
+   * @var mixed[]
+   */
+  protected $values = [];
+
+  /**
+   * {@inheritdoc}
+   */
+  public function &getValues() {
+    return $this->values;
+  }
+}
diff --git a/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php
new file mode 100644
index 0000000..3ec3619
--- /dev/null
+++ b/core/tests/Drupal/Tests/Core/Form/SubformStateTest.php
@@ -0,0 +1,257 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Tests\Core\Form\SubformStateTest.
+ */
+
+namespace Drupal\Tests\Core\Form;
+
+use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Form\FormState;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Form\SubformState;
+use Drupal\Core\Form\SubformStateInterface;
+use Drupal\Tests\UnitTestCase;
+
+/**
+ * @coversDefaultClass \Drupal\Core\Form\SubformState
+ *
+ * @group Form
+ */
+class SubformStateTest extends UnitTestCase {
+
+  /**
+   * Test fixture.
+   *
+   * @var array
+   */
+  protected $initialValues = [
+    'foo' => 'bar',
+    'dog' => [
+      'breed' => 'Pit bull',
+      'name' => 'Dodger',
+    ],
+  ];
+  protected $element = [
+    'foo' => [
+      '#parents' => ['foo'],
+      '#array_parents' => ['foo'],
+    ],
+    'dog' => [
+      '#parents' => ['dog'],
+      '#array_parents' => ['dog'],
+      'breed' => [
+        '#parents' => ['dog', 'breed'],
+        '#array_parents' => ['dog', 'breed'],
+      ],
+      'name' => [
+        '#parents' => ['dog', 'name'],
+        '#array_parents' => ['dog', 'name'],
+      ],
+    ],
+  ];
+
+  /**
+   * @covers ::getValues
+   * @covers ::getParents
+   * @covers ::getSubformProperty
+   *
+   * @dataProvider providerTestGetValues
+   *
+   * @param string[] $parents
+   * @param string $expected
+   */
+  public function testGetValues(array $parents, $expected) {
+    $form_state = new FormState();
+    $form_state->setValues($this->initialValues);
+
+    $element = NestedArray::getValue($this->element, $parents);
+    $subform_state = SubformState::createForSubform($element, $form_state);
+    $sub_values = $subform_state->getValues();
+    $this->assertSame($expected, $sub_values);
+  }
+
+  /**
+   * Provides data to self::testGetValues().
+   */
+  public function providerTestGetValues() {
+    $data = [];
+    $data['exist'] = [
+      ['dog'],
+      $this->initialValues['dog'],
+    ];
+
+    return $data;
+  }
+
+  /**
+   * @covers ::getValues
+   * @covers ::getParents
+   * @covers ::getSubformProperty
+   *
+   * @dataProvider providerTestGetValuesBroken
+   *
+   * @expectedException \UnexpectedValueException
+   *
+   * @param string[] $parents
+   * @param string $expected
+   */
+  public function testGetValuesBroken(array $parents, $expected) {
+    $this->testGetValues($parents, $expected);
+  }
+
+  /**
+   * Provides data to self::testGetValuesBroken().
+   */
+  public function providerTestGetValuesBroken() {
+    $data = [];
+    $data['exist'] = [
+      ['foo'],
+      $this->initialValues['foo'],
+    ];
+    $data['nested'] = [
+      ['dog', 'name'],
+      'Dodger',
+    ];
+
+    return $data;
+  }
+
+  /**
+   * @covers ::getValue
+   *
+   * @dataProvider providerTestGetValue
+   */
+  public function testGetValue($parents, $key, $expected, $default = NULL) {
+    $form_state = new FormState();
+    $form_state->setValues($this->initialValues);
+
+    $element = NestedArray::getValue($this->element, $parents);
+    $subform_state = SubformState::createForSubform($element, $form_state);
+    $sub_values = $subform_state->getValue($key, $default);
+    $this->assertSame($expected, $sub_values);
+  }
+
+  /**
+   * Provides data to self::testGetValue().
+   */
+  public function providerTestGetValue() {
+    $data = [];
+    $data['exist'] = [
+      ['dog'],
+      'name',
+      'Dodger',
+    ];
+
+    return $data;
+  }
+
+  /**
+   * @covers ::getValue
+   *
+   * @dataProvider providerTestGetValueBroken
+   *
+   * @expectedException \UnexpectedValueException
+   */
+  public function testGetValueBroken(array $parents, $key, $expected, $default = NULL) {
+    $this->testGetValue($parents, $key, $expected, $default);
+  }
+
+  /**
+   * Provides data to self::testGetValueBroken().
+   */
+  public function providerTestGetValueBroken() {
+    $data = [];
+    $data['nested'] = [
+      ['dog', 'name'],
+      NULL,
+      'Dodger',
+    ];
+
+    return $data;
+  }
+
+  /**
+   * @covers ::setValues
+   *
+   * @dataProvider providerTestSetValues
+   */
+  public function testSetValues($parents, $new_values, $expected) {
+    $form_state = new FormState();
+    $form_state->setValues($this->initialValues);
+
+    $element = NestedArray::getValue($this->element, $parents);
+    $subform_state = SubformState::createForSubform($element, $form_state);
+    $subform_state->setValues($new_values);
+    $this->assertSame($expected, $form_state->getValues());
+  }
+
+  /**
+   * Provides data to self::testSetValues().
+   */
+  public function providerTestSetValues() {
+    $data = [];
+    $data['exist'] = [
+      ['dog'],
+      [],
+      [
+        'foo' => 'bar',
+        'dog' => [],
+      ],
+    ];
+    return $data;
+  }
+
+  /**
+   * @covers ::setValues
+   *
+   * @dataProvider providerTestSetValuesBroken
+   *
+   * @expectedException \UnexpectedValueException
+   */
+  public function testSetValuesBroken($parents, $new_values, $expected) {
+    $this->testSetValues($parents, $new_values, $expected);
+  }
+
+  /**
+   * Provides data to self::testSetValuesBroken().
+   */
+  public function providerTestSetValuesBroken() {
+    $data = [];
+    $data['exist'] = [
+      ['foo'],
+      [],
+      [
+        'foo' => [],
+        'dog' => $this->initialValues['dog'],
+      ],
+    ];
+    return $data;
+  }
+
+  /**
+   * @covers ::getCompleteFormState
+   */
+  public function testGetCompleteFormStateWithParentCompleteForm() {
+    $decorated_form_state = $this->getMock(FormStateInterface::class);
+    $subform = [];
+    $subform_state = SubformState::createForSubform($subform, $decorated_form_state);
+    $this->assertSame($decorated_form_state, $subform_state->getCompleteFormState());
+  }
+
+  /**
+   * @covers ::getCompleteFormState
+   */
+  public function testGetCompleteFormStateWithParentSubform() {
+    $form_state = $this->getMock(FormStateInterface::class);
+    $decorated_form_state = $this->getMock(SubformStateInterface::class);
+    $decorated_form_state->expects($this->atLeastOnce())
+      ->method('getCompleteFormState')
+      ->willReturn($form_state);
+    $subform = [];
+    $subform_state = SubformState::createForSubform($subform, $decorated_form_state);
+    $this->assertSame($form_state, $subform_state->getCompleteFormState());
+  }
+
+}
