diff --git a/core/lib/Drupal/Core/Form/FormState.php b/core/lib/Drupal/Core/Form/FormState.php index 3d81fb2..8bba317 100644 --- a/core/lib/Drupal/Core/Form/FormState.php +++ b/core/lib/Drupal/Core/Form/FormState.php @@ -326,10 +326,11 @@ public function offsetUnset($offset) { /** * {@inheritdoc} */ - public function setIfNotExists($key, $value) { - if (!array_key_exists($key, $this->formState)) { - $this->set($key, $value); + public function setIfNotExists($property, $value) { + if (!array_key_exists($property, $this->formState)) { + $this->set($property, $value); } + return $this; } /** @@ -348,6 +349,7 @@ public function &get($property) { */ public function set($property, $value) { $this->formState[$property] = $value; + return $this; } /** @@ -417,7 +419,7 @@ public function setErrorByName($name, $message = '') { } } - return $this['errors']; + return $this; } /** @@ -425,6 +427,7 @@ public function setErrorByName($name, $message = '') { */ public function setError(&$element, $message = '') { $this->setErrorByName(implode('][', $element['#parents']), $message); + return $this; } /** diff --git a/core/lib/Drupal/Core/Form/FormStateInterface.php b/core/lib/Drupal/Core/Form/FormStateInterface.php index 7eb07bc..1748fca 100644 --- a/core/lib/Drupal/Core/Form/FormStateInterface.php +++ b/core/lib/Drupal/Core/Form/FormStateInterface.php @@ -56,17 +56,16 @@ public function getCacheableArray(); public function setFormState(array $form_state_additions); /** - * Saves a value for a given key if it does not exist yet. + * Sets a value to an arbitrary property if it does not exist yet. * - * @param string $key - * The key of the data to store. + * @param string $property + * The property to use for the value. * @param mixed $value * The data to store. * - * @return bool - * TRUE if the data was set, FALSE if it already existed. + * @return $this */ - public function setIfNotExists($key, $value); + public function setIfNotExists($property, $value); /** * Sets the redirect URL for the form. @@ -201,14 +200,19 @@ public static function hasAnyErrors(); * @param string $message * (optional) The error message to present to the user. * - * @return mixed - * Return value is for internal use only. To get a list of errors, use - * FormErrorInterface::getErrors() or FormErrorInterface::getError(). + * @return $this */ public function setErrorByName($name, $message = ''); /** * Flags an element as having an error. + * + * @param array $element + * The form element. + * @param string $message + * (optional) The error message to present to the user. + * + * @return $this */ public function setError(&$element, $message = '');