Commit df1a669b authored by webchick's avatar webchick

Issue #2131851 by tim.plunkett: Form errors must be specific to a form and not a global.

parent 53804ea1
......@@ -210,7 +210,7 @@ function authorize_filetransfer_form_validate($form, &$form_state) {
catch (Exception $e) {
// The format of this error message is similar to that used on the
// database connection form in the installer.
form_set_error('connection_settings', t('Failed to connect to the server. The server reports the following message: !message For more help installing or updating code on your server, see the <a href="@handbook_url">handbook</a>.', array(
form_set_error('connection_settings', $form_state, t('Failed to connect to the server. The server reports the following message: !message For more help installing or updating code on your server, see the <a href="@handbook_url">handbook</a>.', array(
'!message' => '<p class="error">' . $e->getMessage() . '</p>',
'@handbook_url' => 'http://drupal.org/documentation/install/modules-themes',
)));
......
......@@ -274,8 +274,8 @@ function form_execute_handlers($type, &$form, &$form_state) {
*
* @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->setErrorByName()
*/
function form_set_error($name = NULL, $message = '', $limit_validation_errors = NULL) {
return \Drupal::formBuilder()->setErrorByName($name, $message, $limit_validation_errors);
function form_set_error($name, array &$form_state, $message = '') {
\Drupal::formBuilder()->setErrorByName($name, $form_state, $message);
}
/**
......@@ -283,8 +283,8 @@ function form_set_error($name = NULL, $message = '', $limit_validation_errors =
*
* @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->clearErrors()
*/
function form_clear_error() {
\Drupal::formBuilder()->clearErrors();
function form_clear_error(array &$form_state) {
\Drupal::formBuilder()->clearErrors($form_state);
}
/**
......@@ -292,8 +292,8 @@ function form_clear_error() {
*
* @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getErrors()
*/
function form_get_errors() {
return \Drupal::formBuilder()->getErrors();
function form_get_errors(array &$form_state) {
return \Drupal::formBuilder()->getErrors($form_state);
}
/**
......@@ -301,8 +301,8 @@ function form_get_errors() {
*
* @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->getError()
*/
function form_get_error($element) {
return \Drupal::formBuilder()->getError($element);
function form_get_error($element, array &$form_state) {
return \Drupal::formBuilder()->getError($element, $form_state);
}
/**
......@@ -310,8 +310,8 @@ function form_get_error($element) {
*
* @deprecated as of Drupal 8.0. Use \Drupal::formBuilder()->setError()
*/
function form_error(&$element, $message = '') {
\Drupal::formBuilder()->setError($element, $message);
function form_error(&$element, array &$form_state, $message = '') {
\Drupal::formBuilder()->setError($element, $form_state, $message);
}
/**
......@@ -1108,11 +1108,11 @@ function password_confirm_validate($element, &$element_state) {
$pass2 = trim($element['pass2']['#value']);
if (!empty($pass1) || !empty($pass2)) {
if (strcmp($pass1, $pass2)) {
form_error($element, t('The specified passwords do not match.'));
form_error($element, $element_state, t('The specified passwords do not match.'));
}
}
elseif ($element['#required'] && !empty($element_state['input'])) {
form_error($element, t('Password field is required.'));
form_error($element, $element_state, t('Password field is required.'));
}
// Password field must be converted from a two-element array into a single
......@@ -1457,7 +1457,7 @@ function form_validate_pattern($element, &$form_state) {
$pattern = '{^(?:' . $element['#pattern'] . ')$}';
if (!preg_match($pattern, $element['#value'])) {
form_error($element, t('%name field is not in the right format.', array('%name' => $element['#title'])));
form_error($element, $form_state, t('%name field is not in the right format.', array('%name' => $element['#title'])));
}
}
}
......@@ -1767,11 +1767,11 @@ function form_validate_table($element, &$form_state) {
}
if ($element['#multiple']) {
if (!is_array($element['#value']) || !count(array_filter($element['#value']))) {
form_error($element, t('No items selected.'));
form_error($element, $form_state, t('No items selected.'));
}
}
elseif (!isset($element['#value']) || $element['#value'] === '') {
form_error($element, t('No item selected.'));
form_error($element, $form_state, t('No item selected.'));
}
}
......@@ -1894,7 +1894,7 @@ function form_process_machine_name($element, &$form_state) {
function form_validate_machine_name(&$element, &$form_state) {
// Verify that the machine name not only consists of replacement tokens.
if (preg_match('@^' . $element['#machine_name']['replace'] . '+$@', $element['#value'])) {
form_error($element, t('The machine-readable name must contain unique characters.'));
form_error($element, $form_state, t('The machine-readable name must contain unique characters.'));
}
// Verify that the machine name contains no disallowed characters.
......@@ -1903,15 +1903,15 @@ function form_validate_machine_name(&$element, &$form_state) {
// Since a hyphen is the most common alternative replacement character,
// a corresponding validation error message is supported here.
if ($element['#machine_name']['replace'] == '-') {
form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and hyphens.'));
form_error($element, $form_state, t('The machine-readable name must contain only lowercase letters, numbers, and hyphens.'));
}
// Otherwise, we assume the default (underscore).
else {
form_error($element, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
form_error($element, $form_state, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
}
}
else {
form_error($element, $element['#machine_name']['error']);
form_error($element, $form_state, $element['#machine_name']['error']);
}
}
......@@ -1919,7 +1919,7 @@ function form_validate_machine_name(&$element, &$form_state) {
if ($element['#default_value'] !== $element['#value']) {
$function = $element['#machine_name']['exists'];
if (call_user_func($function, $element['#value'], $element, $form_state)) {
form_error($element, t('The machine-readable name is already in use. It must be unique.'));
form_error($element, $form_state, t('The machine-readable name is already in use. It must be unique.'));
}
}
}
......@@ -2339,7 +2339,7 @@ function form_validate_email(&$element, &$form_state) {
form_set_value($element, $value, $form_state);
if ($value !== '' && !valid_email_address($value)) {
form_error($element, t('The e-mail address %mail is not valid.', array('%mail' => $value)));
form_error($element, $form_state, t('The e-mail address %mail is not valid.', array('%mail' => $value)));
}
}
......@@ -2415,18 +2415,18 @@ function form_validate_number(&$element, &$form_state) {
// Ensure the input is numeric.
if (!is_numeric($value)) {
form_error($element, t('%name must be a number.', array('%name' => $name)));
form_error($element, $form_state, t('%name must be a number.', array('%name' => $name)));
return;
}
// Ensure that the input is greater than the #min property, if set.
if (isset($element['#min']) && $value < $element['#min']) {
form_error($element, t('%name must be higher than or equal to %min.', array('%name' => $name, '%min' => $element['#min'])));
form_error($element, $form_state, t('%name must be higher than or equal to %min.', array('%name' => $name, '%min' => $element['#min'])));
}
// Ensure that the input is less than the #max property, if set.
if (isset($element['#max']) && $value > $element['#max']) {
form_error($element, t('%name must be lower than or equal to %max.', array('%name' => $name, '%max' => $element['#max'])));
form_error($element, $form_state, t('%name must be lower than or equal to %max.', array('%name' => $name, '%max' => $element['#max'])));
}
if (isset($element['#step']) && strtolower($element['#step']) != 'any') {
......@@ -2435,7 +2435,7 @@ function form_validate_number(&$element, &$form_state) {
$offset = isset($element['#min']) ? $element['#min'] : 0.0;
if (!Number::validStep($value, $element['#step'], $offset)) {
form_error($element, t('%name is not a valid number.', array('%name' => $name)));
form_error($element, $form_state, t('%name is not a valid number.', array('%name' => $name)));
}
}
}
......@@ -2518,7 +2518,7 @@ function form_validate_url(&$element, &$form_state) {
form_set_value($element, $value, $form_state);
if ($value !== '' && !valid_url($value, TRUE)) {
form_error($element, t('The URL %url is not valid.', array('%url' => $value)));
form_error($element, $form_state, t('The URL %url is not valid.', array('%url' => $value)));
}
}
......@@ -2539,7 +2539,7 @@ function form_validate_color(&$element, &$form_state) {
form_set_value($element, Color::rgbToHex(Color::hexToRgb($value)), $form_state);
}
catch (InvalidArgumentException $e) {
form_error($element, t('%name must be a valid color.', array('%name' => empty($element['#title']) ? $element['#parents'][0] : $element['#title'])));
form_error($element, $form_state, t('%name must be a valid color.', array('%name' => empty($element['#title']) ? $element['#parents'][0] : $element['#title'])));
}
}
}
......@@ -2908,7 +2908,7 @@ function _form_set_attributes(&$element, $class = array()) {
$element['#attributes']['required'] = 'required';
$element['#attributes']['aria-required'] = 'true';
}
if (isset($element['#parents']) && form_get_error($element) !== NULL && !empty($element['#validated'])) {
if (isset($element['#parents']) && isset($element['#errors']) && !empty($element['#validated'])) {
$element['#attributes']['class'][] = 'error';
$element['#attributes']['aria-invalid'] = 'true';
}
......
......@@ -653,7 +653,7 @@ function install_run_task($task, &$install_state) {
'build_info' => array('args' => array(&$install_state)),
);
drupal_form_submit($function, $form_state);
$errors = form_get_errors();
$errors = form_get_errors($form_state);
if (!empty($errors)) {
throw new Exception(implode("\n", $errors));
}
......@@ -1192,7 +1192,7 @@ function install_settings_form_validate($form, &$form_state) {
$form_state['storage']['database'] = $database;
$errors = install_database_errors($database, $form_state['values']['settings_file']);
foreach ($errors as $name => $message) {
form_set_error($name, $message);
form_set_error($name, $form_state, $message);
}
}
......@@ -2699,7 +2699,7 @@ function _install_configure_form($form, &$form_state, &$install_state) {
*/
function install_configure_form_validate($form, &$form_state) {
if ($error = user_validate_name($form_state['values']['account']['name'])) {
form_error($form['admin_account']['account']['name'], $error);
form_error($form['admin_account']['account']['name'], $form_state, $error);
}
}
......
......@@ -359,7 +359,7 @@ public function flagErrors(FieldItemListInterface $items, array $form, array &$f
// @todo: Pass $violation->arrayPropertyPath as property path.
$error_element = $this->errorElement($delta_element, $violation, $form, $form_state);
if ($error_element !== FALSE) {
form_error($error_element, $violation->getMessage());
form_error($error_element, $form_state, $violation->getMessage());
}
}
}
......
This diff is collapsed.
......@@ -12,7 +12,7 @@
/**
* Provides an interface for form building and processing.
*/
interface FormBuilderInterface {
interface FormBuilderInterface extends FormErrorInterface {
/**
* Determines the form ID.
......@@ -508,128 +508,6 @@ public function redirectForm($form_state);
*/
public function executeHandlers($type, &$form, &$form_state);
/**
* Files an error against a form element.
*
* When a validation error is detected, the validator calls form_set_error()
* to indicate which element needs to be changed and provide an error message.
* This causes the Form API to not execute the form submit handlers, and
* instead to re-display the form to the user with the corresponding elements
* rendered with an 'error' CSS class (shown as red by default).
*
* The standard form_set_error() behavior can be changed if a button provides
* the #limit_validation_errors property. Multistep forms not wanting to
* validate the whole form can set #limit_validation_errors on buttons to
* limit validation errors to only certain elements. For example, pressing the
* "Previous" button in a multistep form should not fire validation errors
* just because the current step has invalid values. If
* #limit_validation_errors is set on a clicked button, the button must also
* define a #submit property (may be set to an empty array). Any #submit
* handlers will be executed even if there is invalid input, so extreme care
* should be taken with respect to any actions taken by them. This is
* typically not a problem with buttons like "Previous" or "Add more" that do
* not invoke persistent storage of the submitted form values. Do not use the
* #limit_validation_errors property on buttons that trigger saving of form
* values to the database.
*
* The #limit_validation_errors property is a list of "sections" within
* $form_state['values'] that must contain valid values. Each "section" is an
* array with the ordered set of keys needed to reach that part of
* $form_state['values'] (i.e., the #parents property of the element).
*
* Example 1: Allow the "Previous" button to function, regardless of whether
* any user input is valid.
*
* @code
* $form['actions']['previous'] = array(
* '#type' => 'submit',
* '#value' => t('Previous'),
* '#limit_validation_errors' => array(), // No validation.
* '#submit' => array('some_submit_function'), // #submit required.
* );
* @endcode
*
* Example 2: Require some, but not all, user input to be valid to process the
* submission of a "Previous" button.
*
* @code
* $form['actions']['previous'] = array(
* '#type' => 'submit',
* '#value' => t('Previous'),
* '#limit_validation_errors' => array(
* array('step1'), // Validate $form_state['values']['step1'].
* array('foo', 'bar'), // Validate $form_state['values']['foo']['bar'].
* ),
* '#submit' => array('some_submit_function'), // #submit required.
* );
* @endcode
*
* This will require $form_state['values']['step1'] and everything within it
* (for example, $form_state['values']['step1']['choice']) to be valid, so
* calls to form_set_error('step1', $message) or
* form_set_error('step1][choice', $message) will prevent the submit handlers
* from running, and result in the error message being displayed to the user.
* However, calls to form_set_error('step2', $message) and
* form_set_error('step2][groupX][choiceY', $message) will be suppressed,
* resulting in the message not being displayed to the user, and the submit
* handlers will run despite $form_state['values']['step2'] and
* $form_state['values']['step2']['groupX']['choiceY'] containing invalid
* values. Errors for an invalid $form_state['values']['foo'] will be
* suppressed, but errors flagging invalid values for
* $form_state['values']['foo']['bar'] and everything within it will be
* flagged and submission prevented.
*
* Partial form validation is implemented by suppressing errors rather than by
* skipping the input processing and validation steps entirely, because some
* forms have button-level submit handlers that call Drupal API functions that
* assume that certain data exists within $form_state['values'], and while not
* doing anything with that data that requires it to be valid, PHP errors
* would be triggered if the input processing and validation steps were fully
* skipped.
*
* @param $name
* The name of the form element. If the #parents property of your form
* element is array('foo', 'bar', 'baz') then you may set an error on 'foo'
* or 'foo][bar][baz'. Setting an error on 'foo' sets an error for every
* element where the #parents array starts with 'foo'.
* @param $message
* The error message to present to the user.
* @param $limit_validation_errors
* Internal use only. The #limit_validation_errors property of the clicked
* button, if it exists.
*
* @return mixed
* Return value is for internal use only. To get a list of errors, use
* form_get_errors() or form_get_error().
*
* @see http://drupal.org/node/370537
* @see http://drupal.org/node/763376
*/
public function setErrorByName($name = NULL, $message = '', $limit_validation_errors = NULL);
/**
* Clears all errors against all form elements made by form_set_error().
*/
public function clearErrors();
/**
* Returns an associative array of all errors.
*/
public function getErrors();
/**
* Returns the error message filed against the given form element.
*
* Form errors higher up in the form structure override deeper errors as well
* as errors on the element itself.
*/
public function getError($element);
/**
* Flags an element as having an error.
*/
public function setError(&$element, $message = '');
/**
* Builds and processes all elements in the structured form array.
*
......
<?php
/**
* @file
* Contains \Drupal\Core\Form\FormErrorInterface.
*/
namespace Drupal\Core\Form;
/**
* Provides an interface for form error handling.
*/
interface FormErrorInterface {
/**
* Files an error against a form element.
*
* When a validation error is detected, the validator calls form_set_error()
* to indicate which element needs to be changed and provide an error message.
* This causes the Form API to not execute the form submit handlers, and
* instead to re-display the form to the user with the corresponding elements
* rendered with an 'error' CSS class (shown as red by default).
*
* The standard form_set_error() behavior can be changed if a button provides
* the #limit_validation_errors property. Multistep forms not wanting to
* validate the whole form can set #limit_validation_errors on buttons to
* limit validation errors to only certain elements. For example, pressing the
* "Previous" button in a multistep form should not fire validation errors
* just because the current step has invalid values. If
* #limit_validation_errors is set on a clicked button, the button must also
* define a #submit property (may be set to an empty array). Any #submit
* handlers will be executed even if there is invalid input, so extreme care
* should be taken with respect to any actions taken by them. This is
* typically not a problem with buttons like "Previous" or "Add more" that do
* not invoke persistent storage of the submitted form values. Do not use the
* #limit_validation_errors property on buttons that trigger saving of form
* values to the database.
*
* The #limit_validation_errors property is a list of "sections" within
* $form_state['values'] that must contain valid values. Each "section" is an
* array with the ordered set of keys needed to reach that part of
* $form_state['values'] (i.e., the #parents property of the element).
*
* Example 1: Allow the "Previous" button to function, regardless of whether
* any user input is valid.
*
* @code
* $form['actions']['previous'] = array(
* '#type' => 'submit',
* '#value' => t('Previous'),
* '#limit_validation_errors' => array(), // No validation.
* '#submit' => array('some_submit_function'), // #submit required.
* );
* @endcode
*
* Example 2: Require some, but not all, user input to be valid to process the
* submission of a "Previous" button.
*
* @code
* $form['actions']['previous'] = array(
* '#type' => 'submit',
* '#value' => t('Previous'),
* '#limit_validation_errors' => array(
* array('step1'), // Validate $form_state['values']['step1'].
* array('foo', 'bar'), // Validate $form_state['values']['foo']['bar'].
* ),
* '#submit' => array('some_submit_function'), // #submit required.
* );
* @endcode
*
* This will require $form_state['values']['step1'] and everything within it
* (for example, $form_state['values']['step1']['choice']) to be valid, so
* calls to form_set_error('step1', $form_state, $message) or
* form_set_error('step1][choice', $form_state, $message) will prevent the
* submit handlers from running, and result in the error message being
* displayed to the user. However, calls to
* form_set_error('step2', $form_state, $message) and
* form_set_error('step2][groupX][choiceY', $form_state, $message) will be
* suppressed, resulting in the message not being displayed to the user, and
* the submitdoCheckErrors handlers will run despite $form_state['values']['step2'] and
* $form_state['values']['step2']['groupX']['choiceY'] containing invalid
* values. Errors for an invalid $form_state['values']['foo'] will be
* suppressed, but errors flagging invalid values for
* $form_state['values']['foo']['bar'] and everything within it will be
* flagged and submission prevented.
*
* Partial form validation is implemented by suppressing errors rather than by
* skipping the input processing and validation steps entirely, because some
* forms have button-level submit handlers that call Drupal API functions that
* assume that certain data exists within $form_state['values'], and while not
* doing anything with that data that requires it to be valid, PHP errors
* would be triggered if the input processing and validation steps were fully
* skipped.
*
* @param $name
* The name of the form element. If the #parents property of your form
* element is array('foo', 'bar', 'baz') then you may set an error on 'foo'
* or 'foo][bar][baz'. Setting an error on 'foo' sets an error for every
* element where the #parents array starts with 'foo'.
* @param array $form_state
* An associative array containing the current state of the form.
* @param $message
* The error message to present to the user.
*
* @return mixed
* Return value is for internal use only. To get a list of errors, use
* form_get_errors() or form_get_error().
*
* @see http://drupal.org/node/370537
* @see http://drupal.org/node/763376
*/
public function setErrorByName($name, array &$form_state, $message = '');
/**
* Clears all errors against all form elements made by form_set_error().
*
* @param array $form_state
* An associative array containing the current state of the form.
*/
public function clearErrors(array &$form_state);
/**
* Returns an associative array of all errors.
*
* @param array $form_state
* An associative array containing the current state of the form.
*
* @return array
* An array of all errors, keyed by the name of the form element.
*/
public function getErrors(array $form_state);
/**
* Returns the error message filed against the given form element.
*
* Form errors higher up in the form structure override deeper errors as well
* as errors on the element itself.
*
* @param array $element
* The form element to check for errors.
* @param array $form_state
* An associative array containing the current state of the form.
*
* @return string|null
* Either the error message for this element or NULL if there are no errors.
*/
public function getError($element, array &$form_state);
/**
* Flags an element as having an error.
*/
public function setError(&$element, array &$form_state, $message = '');
/**
* Returns if there have been any errors during build.
*
* This will include any forms built during this request.
*
* @return bool
* Whether there have been any errors.
*/
public function getAnyErrors();
}
......@@ -148,7 +148,7 @@ public function buildConfigurationForm(array $form, array &$form_state) {
public function validateConfigurationForm(array &$form, array &$form_state) {
if (!valid_email_address($form_state['values']['recipient']) && strpos($form_state['values']['recipient'], ':mail') === FALSE) {
// We want the literal %author placeholder to be emphasized in the error message.
form_set_error('recipient', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
form_set_error('recipient', $form_state, t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
}
}
......
......@@ -122,10 +122,10 @@ public function validate(array $form, array &$form_state) {
$result = $feed_storage_controller->getFeedDuplicates($feed);
foreach ($result as $item) {
if (strcasecmp($item->title, $feed->label()) == 0) {
form_set_error('title', $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
form_set_error('title', $form_state, $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
}
if (strcasecmp($item->url, $feed->url->value) == 0) {
form_set_error('url', $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->url->value)));
form_set_error('url', $form_state, $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->url->value)));
}
}
parent::validate($form, $form_state);
......
......@@ -125,7 +125,7 @@ public function validateForm(array &$form, array &$form_state) {
$unique = $this->categoryStorageController->isUnique($title);
}
if (!$unique) {
form_set_error('title', $this->t('A category named %category already exists. Enter a unique title.', array('%category' => $title)));
form_set_error('title', $form_state, $this->t('A category named %category already exists. Enter a unique title.', array('%category' => $title)));
}
}
}
......
......@@ -139,7 +139,7 @@ public function buildForm(array $form, array &$form_state) {
public function validateForm(array &$form, array &$form_state) {
// If both fields are empty or filled, cancel.
if (empty($form_state['values']['remote']) == empty($_FILES['files']['name']['upload'])) {
form_set_error('remote', $this->t('You must <em>either</em> upload a file or enter a URL.'));
form_set_error('remote', $form_state, $this->t('You must <em>either</em> upload a file or enter a URL.'));
}
}
......@@ -148,7 +148,7 @@ public function validateForm(array &$form, array &$form_state) {
*/
public function submitForm(array &$form, array &$form_state) {
$validators = array('file_validate_extensions' => array('opml xml'));
if ($file = file_save_upload('upload', $validators, FALSE, 0)) {
if ($file = file_save_upload('upload', $form_state, $validators, FALSE, 0)) {
$data = file_get_contents($file->getFileUri());
}
else {
......
......@@ -105,13 +105,13 @@ public function buildForm(array $form, array &$form_state, $default_ip = '') {
public function validateForm(array &$form, array &$form_state) {
$ip = trim($form_state['values']['ip']);
if ($this->ipManager->isBanned($ip)) {
form_set_error('ip', $this->t('This IP address is already banned.'));
form_set_error('ip', $form_state, $this->t('This IP address is already banned.'));
}
elseif ($ip == $this->getRequest()->getClientIP()) {
form_set_error('ip', $this->t('You may not ban your own IP address.'));
form_set_error('ip', $form_state, $this->t('You may not ban your own IP address.'));
}
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
form_set_error('ip', $this->t('Enter a valid IP address.'));
form_set_error('ip', $form_state, $this->t('Enter a valid IP address.'));
}
}
......
......@@ -238,7 +238,7 @@ public function validateForm(array &$form, array &$form_state) {
// @todo Inject this once https://drupal.org/node/2060865 is in.
$exists = \Drupal::entityManager()->getStorageController('custom_block')->loadByProperties(array('info' => $form_state['values']['info']));
if (!empty($exists)) {
form_set_error('info', t('A block with description %name already exists.', array(
form_set_error('info', $form_state, t('A block with description %name already exists.', array(
'%name' => $form_state['values']['info']
)));
}
......
......@@ -148,7 +148,7 @@ public function blockValidate($form, &$form_state) {}
*/
public function submitConfigurationForm(array &$form, array &$form_state) {
// Process the block's submission handling if no errors occurred only.
if (!form_get_errors()) {
if (!form_get_errors($form_state)) {
$this->configuration['label'] = $form_state['values']['label'];
$this->configuration['label_display'] = $form_state['values']['label_display'];
$this->configuration['module'] = $form_state['values']['module'];
......
......@@ -313,8 +313,10 @@ public function submit(array $form, array &$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 = array(
'values' => &$form_state['values']['settings']
'values' => &$form_state['values']['settings'],
'errors' => $form_state['errors'],
);
// Call the plugin submit handler.
$entity->getPlugin()->submitConfigurationForm($form, $settings);
......
......@@ -96,7 +96,7 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node =
*/
public function validateForm(array &$form, array &$form_state) {
if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) {
form_set_error('', $this->t('This book has been modified by another user, the changes could not be saved.'));
form_set_error('', $form_state, $this->t('This book has been modified by another user, the changes could not be saved.'));
}
}
......
......@@ -53,7 +53,7 @@ public function buildForm(array $form, array &$form_state) {