Commit 537457b5 authored by alexpott's avatar alexpott

Issue #2308821 by tim.plunkett: Replace FormErrorInterface with...

Issue #2308821 by tim.plunkett: Replace FormErrorInterface with $form_state->setErrorByName() and $form_state->setError().
parent 9bc009b1
......@@ -163,48 +163,48 @@ function form_execute_handlers($type, &$form, FormStateInterface $form_state) {
* Files an error against a form element.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::formBuilder()->setErrorByName().
* Use $form_state->setErrorByName().
*
* @see \Drupal\Core\Form\FormErrorInterface::setErrorByName().
* @see \Drupal\Core\Form\FormStateInterface::setErrorByName().
*/
function form_set_error($name, FormStateInterface $form_state, $message = '') {
\Drupal::formBuilder()->setErrorByName($name, $form_state, $message);
$form_state->setErrorByName($name, $message);
}
/**
* Returns an associative array of all errors.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::formBuilder()->getErrors().
* Use $form_state->getErrors().
*
* @see \Drupal\Core\Form\FormErrorInterface::getErrors()
* @see \Drupal\Core\Form\FormStateInterface::getErrors()
*/
function form_get_errors(FormStateInterface $form_state) {
return \Drupal::formBuilder()->getErrors($form_state);
return $form_state->getErrors();
}
/**
* Returns the error message filed against the given form element.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::formBuilder()->getError().
* Use $form_state->getError().
*
* @see \Drupal\Core\Form\FormErrorInterface::getError().
* @see \Drupal\Core\Form\FormStateInterface::getError().
*/
function form_get_error($element, FormStateInterface $form_state) {
return \Drupal::formBuilder()->getError($element, $form_state);
return $form_state->getError($element);
}
/**
* Flags an element as having an error.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal::formBuilder()->setError().
* Use $form_state->setError().
*
* @see \Drupal\Core\Form\FormErrorInterface::setError().
* @see \Drupal\Core\Form\FormStateInterface::setError().
*/
function form_error(&$element, FormStateInterface $form_state, $message = '') {
\Drupal::formBuilder()->setError($element, $form_state, $message);
$form_state->setError($element, $message);
}
/**
......
......@@ -832,7 +832,7 @@ function install_get_form($form_id, array &$install_state) {
$form_builder->submitForm($form_id, $form_state);
// Throw an exception in case of any form validation error.
if ($errors = $form_builder->getErrors($form_state)) {
if ($errors = $form_state->getErrors()) {
throw new InstallerException(implode("\n", $errors));
}
}
......
......@@ -389,7 +389,7 @@ public function flagErrors(FieldItemListInterface $items, ConstraintViolationLis
// @todo Field validation should not be run on fields with FAPI errors to
// begin with. See https://drupal.org/node/2070429.
$element_path = implode('][', $element['#parents']);
if ($reported_errors = $form_builder->getErrors($form_state)) {
if ($reported_errors = $form_state->getErrors()) {
foreach (array_keys($reported_errors) as $error_path) {
if (strpos($error_path, $element_path) === 0) {
return;
......@@ -431,7 +431,7 @@ public function flagErrors(FieldItemListInterface $items, ConstraintViolationLis
// @todo: Pass $violation->arrayPropertyPath as property path.
$error_element = $this->errorElement($delta_element, $violation, $form, $form_state);
if ($error_element !== FALSE) {
$form_builder->setError($error_element, $form_state, $violation->getMessage());
$form_state->setError($error_element, $violation->getMessage());
}
}
}
......
......@@ -158,7 +158,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
catch (\Exception $e) {
// The format of this error message is similar to that used on the
// database connection form in the installer.
$this->setFormError('connection_settings', $form_state, $this->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_state->setErrorByName('connection_settings', $this->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',
)));
......
......@@ -173,27 +173,6 @@ private function container() {
return \Drupal::getContainer();
}
/**
* Files an error against a form element.
*
* @param string $name
* The name of the form element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param string $message
* (optional) The error message to present to the user.
*
* @deprecated Use \Drupal\Core\Form\FormStateInterface::setErrorByName().
*
* @todo Remove in https://www.drupal.org/node/2308821.
*
* @return $this
*/
protected function setFormError($name, FormStateInterface $form_state, $message = '') {
$form_state->setErrorByName($name, $message);
return $this;
}
/**
* Gets the logger for a specific channel.
*
......
......@@ -397,7 +397,7 @@ public function submitForm($form_arg, FormStateInterface &$form_state) {
// Reset form validation.
$form_state->set('must_validate', TRUE);
$this->clearErrors($form_state);
$form_state->clearErrors();
$this->prepareForm($form_id, $form, $form_state);
$this->processForm($form_id, $form, $form_state);
......@@ -494,12 +494,12 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
// form is processed, so scenarios that result in the form being built
// behind the scenes and again for the browser don't increment all the
// element IDs needlessly.
if (!$this->getAnyErrors()) {
if (!FormState::hasAnyErrors()) {
// In case of errors, do not break HTML IDs of other forms.
$this->drupalStaticReset('drupal_html_id');
}
if (!$form_state['rebuild'] && !$this->formValidator->getAnyErrors()) {
if (!$form_state['rebuild'] && !FormState::hasAnyErrors()) {
if ($submit_response = $this->formSubmitter->doSubmitForm($form, $form_state)) {
return $submit_response;
}
......@@ -525,7 +525,7 @@ public function processForm($form_id, &$form, FormStateInterface &$form_state) {
// along with element-level #submit properties, it makes no sense to
// have divergent form execution based on whether the triggering element
// has #executes_submit_callback set to TRUE.
if (($form_state['rebuild'] || !$form_state['executed']) && !$this->getAnyErrors()) {
if (($form_state['rebuild'] || !$form_state['executed']) && !FormState::hasAnyErrors()) {
// Form building functions (e.g., self::handleInputElement()) may use
// $form_state['rebuild'] to determine if they are running in the
// context of a rebuild, so ensure it is set.
......@@ -685,48 +685,6 @@ public function doSubmitForm(&$form, FormStateInterface &$form_state) {
throw new \LogicException('Use FormBuilderInterface::processForm() instead.');
}
/**
* {@inheritdoc}
*/
public function setErrorByName($name, FormStateInterface &$form_state, $message = '') {
$this->formValidator->setErrorByName($name, $form_state, $message);
}
/**
* {@inheritdoc}
*/
public function clearErrors(FormStateInterface &$form_state) {
$this->formValidator->clearErrors($form_state);
}
/**
* {@inheritdoc}
*/
public function getErrors(FormStateInterface &$form_state) {
return $this->formValidator->getErrors($form_state);
}
/**
* {@inheritdoc}
*/
public function getAnyErrors() {
return $this->formValidator->getAnyErrors();
}
/**
* {@inheritdoc}
*/
public function getError($element, FormStateInterface &$form_state) {
return $this->formValidator->getError($element, $form_state);
}
/**
* {@inheritdoc}
*/
public function setError(&$element, FormStateInterface &$form_state, $message = '') {
$this->formValidator->setError($element, $form_state, $message);
}
/**
* {@inheritdoc}
*/
......
......@@ -10,7 +10,7 @@
/**
* Provides an interface for form building and processing.
*/
interface FormBuilderInterface extends FormErrorInterface {
interface FormBuilderInterface {
/**
* Determines the ID of a form.
......
<?php
/**
* @file
* Contains \Drupal\Core\Form\FormErrorInterface.
*/
namespace Drupal\Core\Form;
/**
* Provides an interface for form error handling.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
* Use \Drupal\Core\Form\FormStateInterface directly.
*/
interface FormErrorInterface {
/**
* Files an error against a form element.
*
* When a validation error is detected, the validator calls this method 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 behavior of this method 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 FormErrorInterface::setErrorByName('step1', $form_state, $message)
* or
* FormErrorInterface::setErrorByName('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
* FormErrorInterface::setErrorByName('step2', $form_state, $message) and
* FormErrorInterface::setErrorByName('step2][groupX][choiceY', $form_state, $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 string $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 \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @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().
*/
public function setErrorByName($name, FormStateInterface &$form_state, $message = '');
/**
* Clears all errors against all form elements made by FormErrorInterface::setErrorByName().
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function clearErrors(FormStateInterface &$form_state);
/**
* Returns an associative array of all errors.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* An array of all errors, keyed by the name of the form element.
*/
public function getErrors(FormStateInterface &$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 \Drupal\Core\Form\FormStateInterface $form_state
* 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, FormStateInterface &$form_state);
/**
* Flags an element as having an error.
*/
public function setError(&$element, FormStateInterface &$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();
}
......@@ -227,16 +227,13 @@ public static function hasAnyErrors();
*
* This will require $form_state['values']['step1'] and everything within it
* (for example, $form_state['values']['step1']['choice']) to be valid, so
* calls to FormErrorInterface::setErrorByName('step1', $form_state, $message)
* or
* FormErrorInterface::setErrorByName('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
* FormErrorInterface::setErrorByName('step2', $form_state, $message) and
* FormErrorInterface::setErrorByName('step2][groupX][choiceY', $form_state, $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
* calls to self::setErrorByName('step1', $message) or
* self::setErrorByName('step1][choice', $message) will prevent the submit
* handlers from running, and result in the error message being displayed to
* the user. However, calls to self::setErrorByName('step2', $message) and
* self::setErrorByName('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
......@@ -276,7 +273,7 @@ public function setErrorByName($name, $message = '');
public function setError(&$element, $message = '');
/**
* Clears all errors against all form elements made by FormErrorInterface::setErrorByName().
* Clears all errors against all form elements made by self::setErrorByName().
*/
public function clearErrors();
......
......@@ -95,7 +95,7 @@ public function validateForm($form_id, &$form, FormStateInterface &$form_state)
$url = $this->requestStack->getCurrentRequest()->getRequestUri();
// Setting this error will cause the form to fail validation.
$this->setErrorByName('form_token', $form_state, $this->t('The form has become outdated. Copy any unsaved work in the form below and then <a href="@link">reload this page</a>.', array('@link' => $url)));
$form_state->setErrorByName('form_token', $this->t('The form has become outdated. Copy any unsaved work in the form below and then <a href="@link">reload this page</a>.', array('@link' => $url)));
// Stop here and don't run any further validation handlers, because they
// could invoke non-safe operations which opens the door for CSRF
......@@ -261,17 +261,17 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
// variables are also known to be defined and we can test them again.
if (isset($is_empty_value) && ($is_empty_multiple || $is_empty_string || $is_empty_value)) {
if (isset($elements['#required_error'])) {
$this->setError($elements, $form_state, $elements['#required_error']);
$form_state->setError($elements, $elements['#required_error']);
}
// A #title is not mandatory for form elements, but without it we cannot
// set a form error message. So when a visible title is undesirable,
// form constructors are encouraged to set #title anyway, and then set
// #title_display to 'invisible'. This improves accessibility.
elseif (isset($elements['#title'])) {
$this->setError($elements, $form_state, $this->t('!name field is required.', array('!name' => $elements['#title'])));
$form_state->setError($elements, $this->t('!name field is required.', array('!name' => $elements['#title'])));
}
else {
$this->setError($elements, $form_state);
$form_state->setError($elements);
}
}
......@@ -303,7 +303,7 @@ protected function doValidateForm(&$elements, FormStateInterface &$form_state, $
protected function performRequiredValidation(&$elements, FormStateInterface &$form_state) {
// Verify that the value is not longer than #maxlength.
if (isset($elements['#maxlength']) && Unicode::strlen($elements['#value']) > $elements['#maxlength']) {
$this->setError($elements, $form_state, $this->t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => Unicode::strlen($elements['#value']))));
$form_state->setError($elements, $this->t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => Unicode::strlen($elements['#value']))));
}
if (isset($elements['#options']) && isset($elements['#value'])) {
......@@ -317,7 +317,7 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
$value = in_array($elements['#type'], array('checkboxes', 'tableselect')) ? array_keys($elements['#value']) : $elements['#value'];
foreach ($value as $v) {
if (!isset($options[$v])) {
$this->setError($elements, $form_state, $this->t('An illegal choice has been detected. Please contact the site administrator.'));
$form_state->setError($elements, $this->t('An illegal choice has been detected. Please contact the site administrator.'));
$this->watchdog('form', 'Illegal choice %choice in !name element.', array('%choice' => $v, '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
}
}
......@@ -336,7 +336,7 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
NestedArray::setValue($form_state['values'], $elements['#parents'], NULL, TRUE);
}
elseif (!isset($options[$elements['#value']])) {
$this->setError($elements, $form_state, $this->t('An illegal choice has been detected. Please contact the site administrator.'));
$form_state->setError($elements, $this->t('An illegal choice has been detected. Please contact the site administrator.'));
$this->watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
}
}
......@@ -352,16 +352,16 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
*/
protected function determineLimitValidationErrors(FormStateInterface &$form_state) {
// While this element is being validated, it may be desired that some
// calls to self::setErrorByName() be suppressed and not result in a form
// error, so that a button that implements low-risk functionality (such as
// "Previous" or "Add more") that doesn't require all user input to be
// valid can still have its submit handlers triggered. The triggering
// element's #limit_validation_errors property contains the information
// for which errors are needed, and all other errors are to be suppressed.
// The #limit_validation_errors property is ignored if submit handlers
// will run, but the element doesn't have a #submit property, because it's
// too large a security risk to have any invalid user input when executing
// form-level submit handlers.
// calls to \Drupal\Core\Form\FormStateInterface::setErrorByName() be
// suppressed and not result in a form error, so that a button that
// implements low-risk functionality (such as "Previous" or "Add more") that
// doesn't require all user input to be valid can still have its submit
// handlers triggered. The triggering element's #limit_validation_errors
// property contains the information for which errors are needed, and all
// other errors are to be suppressed. The #limit_validation_errors property
// is ignored if submit handlers will run, but the element doesn't have a
// #submit property, because it's too large a security risk to have any
// invalid user input when executing form-level submit handlers.
if (isset($form_state['triggering_element']['#limit_validation_errors']) && ($form_state['triggering_element']['#limit_validation_errors'] !== FALSE) && !($form_state['submitted'] && !isset($form_state['triggering_element']['#submit']))) {
return $form_state['triggering_element']['#limit_validation_errors'];
}
......@@ -389,8 +389,7 @@ protected function determineLimitValidationErrors(FormStateInterface &$form_stat
/**
* Stores the errors of each element directly on the element.
*
* Because self::getError() and self::getErrors() require the $form_state,
* we must provide a way for non-form functions to check the errors for a
* We must provide a way for non-form functions to check the errors for a
* specific element. The most common usage of this is a #pre_render callback.
*
* @param array $elements
......@@ -406,49 +405,7 @@ protected function setElementErrorsFromFormState(array &$elements, FormStateInte
}
}
// Store the errors for this element on the element directly.
$elements['#errors'] = $this->getError($elements, $form_state);
}
/**
* {@inheritdoc}
*/
public function setErrorByName($name, FormStateInterface &$form_state, $message = '') {
return $form_state->setErrorByName($name, $message);
}
/**
* {@inheritdoc}
*/
public function setError(&$element, FormStateInterface &$form_state, $message = '') {
return $form_state->setError($element, $message);
}
/**
* {@inheritdoc}
*/
public function getError($element, FormStateInterface &$form_state) {
return $form_state->getError($element);
}
/**
* {@inheritdoc}
*/
public function clearErrors(FormStateInterface &$form_state) {
$form_state->clearErrors();
}
/**
* {@inheritdoc}
*/
public function getErrors(FormStateInterface &$form_state) {
return $form_state->getErrors();
}
/**
* {@inheritdoc}
*/
public function getAnyErrors() {
return FormState::hasAnyErrors();
$elements['#errors'] = $form_state->getError($elements);
}
/**
......
......@@ -10,7 +10,7 @@
/**
* Provides an interface for validating form submissions.
*/
interface FormValidatorInterface extends FormErrorInterface {
interface FormValidatorInterface {
/**
* Executes custom validation handlers for a given form.
......
......@@ -230,7 +230,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($error = user_validate_name($form_state['values']['account']['name'])) {
$this->setFormError('account][name', $form_state, $error);
$form_state->setErrorByName('account][name', $error);
}
}
......
......@@ -128,7 +128,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state['storage']['database'] = $database;
$errors = install_database_errors($database, $form_state['values']['settings_file']);
foreach ($errors as $name => $message) {
$this->setFormError($name, $form_state, $message);
$form_state->setErrorByName($name, $message);
}
}
......
......@@ -49,10 +49,10 @@ public function validate(array $form, FormStateInterface $form_state) {
$result = $feed_storage->getFeedDuplicates($feed);
foreach ($result as $item) {
if (strcasecmp($item->label(), $feed->label()) == 0) {
$this->setFormError('title', $form_state, $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
$form_state->setErrorByName('title', $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
}
if (strcasecmp($item->getUrl(), $feed->getUrl()) == 0) {
$this->setFormError('url', $form_state, $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->getUrl())));
$form_state->setErrorByName('url', $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->getUrl())));
}
}
parent::validate($form, $form_state);
......
......@@ -106,7 +106,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
// If both fields are empty or filled, cancel.
$file_upload = $this->getRequest()->files->get('files[upload]', NULL, TRUE);
if (empty($form_state['values']['remote']) == empty($file_upload)) {
$this->setFormError('remote', $form_state, $this->t('<em>Either</em> upload a file or enter a URL.'));
$form_state->setErrorByName('remote', $this->t('<em>Either</em> upload a file or enter a URL.'));
}
}
......
......@@ -107,13 +107,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $default_
public function validateForm(array &$form, FormStateInterface $form_state) {
$ip = trim($form_state['values']['ip']);
if ($this->ipManager->isBanned($ip)) {
$this->setFormError('ip', $form_state, $this->t('This IP address is already banned.'));
$form_state->setErrorByName('ip', $this->t('This IP address is already banned.'));
}
elseif ($ip == $this->getRequest()->getClientIP()) {
$this->setFormError('ip', $form_state, $this->t('You may not ban your own IP address.'));
$form_state->setErrorByName('ip', $this->t('You may not ban your own IP address.'));
}
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) == FALSE) {
$this->setFormError('ip', $form_state, $this->t('Enter a valid IP address.'));
$form_state->setErrorByName('ip', $this->t('Enter a valid IP address.'));
}
}
......
......@@ -242,7 +242,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
if ($this->entity->isNew()) {
$exists = $this->blockContentStorage->loadByProperties(array('info' => $form_state['values']['info']));
if (!empty($exists)) {
$this->setFormError('info', $form_state, $this->t('A block with description %name already exists.', array(
$form_state->setErrorByName('info', $this->t('A block with description %name already exists.', array(
'%name' => $form_state['values']['info'][0]['value'],
)));
}
......
......@@ -86,7 +86,7 @@ public function buildForm(array $form, FormStateInterface $form_state, NodeInter
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state['values']['tree_hash'] != $form_state['values']['tree_current_hash']) {
$this->setFormError('', $form_state, $this->t('This book has been modified by another user, the changes could not be saved.'));
$form_state->setErrorByName('', $this->t('This book has been modified by another user, the changes could not be saved.'));
}
}
......
......@@ -54,7 +54,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state) {
$child_type = $form_state['values']['book_child_type'];
if (empty($form_state['values']['book_allowed_types'][$child_type])) {
$this->setFormError('book_child_type', $form_state, $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page'))));
$form_state->setErrorByName('book_child_type', $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page'))));
}
parent::validateForm($form, $form_state);
......
......@@ -268,10 +268,10 @@ public function validate(array $form, FormStateInterface $form_state) {
$date = $form_state['values']['date'];
if ($date instanceOf DrupalDateTime && $date->hasErrors()) {
$this->setFormError('date', $form_state, $this->t('You have to specify a valid date.'));
$form_state->setErrorByName('date', $this->t('You have to specify a valid date.'));
}
if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) {
$this->setFormError('name', $form_state, $this->t('You have to specify a valid author.'));
$form_state->setErrorByName('name', $this->t('You have to specify a valid author.'));
}
}
elseif ($form_state