From d39c014754b051475db940873a908ef688f141e5 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Fri, 12 Sep 2014 19:57:00 +0100 Subject: [PATCH] Issue #2334383 by jbrown, ashutoshsngh, er.pushpinderrana: Remove usage of form_error(). --- core/includes/form.inc | 12 ------------ .../Drupal/Core/Render/Element/MachineName.php | 10 +++++----- .../src/Plugin/CKEditorPlugin/StylesCombo.php | 2 +- .../src/Plugin/EditorPluginInterface.php | 2 +- .../selection/SelectionBase.php | 6 +++--- core/modules/file/file.module | 6 +++--- .../src/Plugin/Field/FieldType/FileItem.php | 4 ++-- .../src/Plugin/Field/FieldType/ImageItem.php | 2 +- .../rest/src/Plugin/views/row/DataFieldRow.php | 3 +-- .../Form/FormTestLimitValidationErrorsForm.php | 2 +- .../src/Form/FormTestValidateRequiredForm.php | 2 +- .../Plugin/views/filter/TaxonomyIndexTid.php | 2 +- .../user/src/Plugin/views/access/Role.php | 2 +- .../user/src/Plugin/views/filter/Name.php | 2 +- .../selection/ViewsSelection.php | 2 +- .../views/src/Plugin/views/cache/Time.php | 2 +- .../Plugin/views/display/DisplayPluginBase.php | 8 ++++---- .../views/src/Plugin/views/display/Page.php | 6 +++--- .../src/Plugin/views/field/Serialized.php | 2 +- .../views/src/Plugin/views/filter/Date.php | 10 +++++----- .../Plugin/views/filter/FilterPluginBase.php | 18 ++++++++---------- .../src/Plugin/views/display/DisplayTest.php | 2 +- core/modules/views/views.module | 2 +- 23 files changed, 47 insertions(+), 62 deletions(-) diff --git a/core/includes/form.inc b/core/includes/form.inc index 4764d198549..360155e5024 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -84,18 +84,6 @@ function form_execute_handlers($type, &$form, FormStateInterface $form_state) { } } -/** - * Flags an element as having an error. - * - * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. - * Use $form_state->setError(). - * - * @see \Drupal\Core\Form\FormStateInterface::setError(). - */ -function form_error(&$element, FormStateInterface $form_state, $message = '') { - $form_state->setError($element, $message); -} - /** * Builds and processes all elements in the structured form array. * diff --git a/core/lib/Drupal/Core/Render/Element/MachineName.php b/core/lib/Drupal/Core/Render/Element/MachineName.php index 6b9a29b963e..fb57c5245d5 100644 --- a/core/lib/Drupal/Core/Render/Element/MachineName.php +++ b/core/lib/Drupal/Core/Render/Element/MachineName.php @@ -193,7 +193,7 @@ class MachineName extends Textfield { public static function validateMachineName(&$element, FormStateInterface $form_state, &$complete_form) { // Verify that the machine name not only consists of replacement tokens. if (preg_match('@^' . $element['#machine_name']['replace'] . '+$@', $element['#value'])) { - form_error($element, $form_state, t('The machine-readable name must contain unique characters.')); + $form_state->setError($element, t('The machine-readable name must contain unique characters.')); } // Verify that the machine name contains no disallowed characters. @@ -202,15 +202,15 @@ class MachineName extends Textfield { // 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, $form_state, t('The machine-readable name must contain only lowercase letters, numbers, and hyphens.')); + $form_state->setError($element, t('The machine-readable name must contain only lowercase letters, numbers, and hyphens.')); } // Otherwise, we assume the default (underscore). else { - form_error($element, $form_state, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.')); + $form_state->setError($element, t('The machine-readable name must contain only lowercase letters, numbers, and underscores.')); } } else { - form_error($element, $form_state, $element['#machine_name']['error']); + $form_state->setError($element, $element['#machine_name']['error']); } } @@ -218,7 +218,7 @@ class MachineName extends Textfield { if ($element['#default_value'] !== $element['#value']) { $function = $element['#machine_name']['exists']; if (call_user_func($function, $element['#value'], $element, $form_state)) { - form_error($element, $form_state, t('The machine-readable name is already in use. It must be unique.')); + $form_state->setError($element, t('The machine-readable name is already in use. It must be unique.')); } } } diff --git a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php index 963436df361..d56993027de 100644 --- a/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php +++ b/core/modules/ckeditor/src/Plugin/CKEditorPlugin/StylesCombo.php @@ -97,7 +97,7 @@ class StylesCombo extends CKEditorPluginBase implements CKEditorPluginConfigurab */ public function validateStylesValue(array $element, FormStateInterface $form_state) { if ($this->generateStylesSetSetting($element['#value']) === FALSE) { - form_error($element, $form_state, t('The provided list of styles is syntactically incorrect.')); + $form_state->setError($element, t('The provided list of styles is syntactically incorrect.')); } } diff --git a/core/modules/editor/src/Plugin/EditorPluginInterface.php b/core/modules/editor/src/Plugin/EditorPluginInterface.php index 26300ce0d4a..f5177f515ed 100644 --- a/core/modules/editor/src/Plugin/EditorPluginInterface.php +++ b/core/modules/editor/src/Plugin/EditorPluginInterface.php @@ -57,7 +57,7 @@ interface EditorPluginInterface extends PluginInspectionInterface { * Validates the settings form for an editor. * * The contents of the editor settings are located in - * $form_state->getValue(array('editor', 'settings')). Calls to form_error() + * $form_state->getValue(array('editor', 'settings')). Calls to $form_state->setError() * should reflect this location in the settings form. * * @param array $form diff --git a/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php index fbb653706b2..aba32fd44c9 100644 --- a/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/entity_reference/src/Plugin/entity_reference/selection/SelectionBase.php @@ -243,13 +243,13 @@ class SelectionBase implements SelectionInterface { if (empty($entities)) { if ($strict) { // Error if there are no entities available for a required field. - form_error($element, $form_state, t('There are no entities matching "%value".', $params)); + $form_state->setError($element, t('There are no entities matching "%value".', $params)); } } elseif (count($entities) > 5) { $params['@id'] = key($entities); // Error if there are more than 5 matching entities. - form_error($element, $form_state, t('Many entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)".', $params)); + $form_state->setError($element, t('Many entities are called %value. Specify the one you want by appending the id in parentheses, like "@value (@id)".', $params)); } elseif (count($entities) > 1) { // More helpful error if there are only a few matching entities. @@ -258,7 +258,7 @@ class SelectionBase implements SelectionInterface { $multiples[] = $name . ' (' . $id . ')'; } $params['@id'] = $id; - form_error($element, $form_state, t('Multiple entities match this reference; "%multiple". Specify the one you want by appending the id in parentheses, like "@value (@id)".', array('%multiple' => implode('", "', $multiples)))); + $form_state->setError($element, t('Multiple entities match this reference; "%multiple". Specify the one you want by appending the id in parentheses, like "@value (@id)".', array('%multiple' => implode('", "', $multiples)))); } else { // Take the one and only matching entity. diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 104ef862443..03e10bfea39 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1339,19 +1339,19 @@ function file_managed_file_validate(&$element, FormStateInterface $form_state) { if ($file->isPermanent()) { $references = \Drupal::service('file.usage')->listUsage($file); if (empty($references)) { - form_error($element, $form_state, t('The file used in the !name field may not be referenced.', array('!name' => $element['#title']))); + $form_state->setError($element, t('The file used in the !name field may not be referenced.', array('!name' => $element['#title']))); } } } else { - form_error($element, $form_state, t('The file referenced by the !name field does not exist.', array('!name' => $element['#title']))); + $form_state->setError($element, t('The file referenced by the !name field does not exist.', array('!name' => $element['#title']))); } } } // Check required property based on the FID. if ($element['#required'] && empty($element['fids']['#value']) && !in_array($clicked_button, array('upload_button', 'remove_button'))) { - form_error($element['upload'], $form_state, t('!name field is required.', array('!name' => $element['#title']))); + $form_state->setError($element['upload'], t('!name field is required.', array('!name' => $element['#title']))); } // Consolidate the array value of this field to array of FIDs. diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php index b09746fac78..c84da267774 100644 --- a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php @@ -233,7 +233,7 @@ class FileItem extends EntityReferenceItem { $extensions = array_filter(explode(' ', $extensions)); $extensions = implode(' ', array_unique($extensions)); if (!preg_match('/^([a-z0-9]+([.][a-z0-9])* ?)+$/', $extensions)) { - form_error($element, $form_state, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.')); + $form_state->setError($element, t('The list of allowed extensions is not valid, be sure to exclude leading dots and to separate extensions with a comma or space.')); } else { form_set_value($element, $extensions, $form_state); @@ -252,7 +252,7 @@ class FileItem extends EntityReferenceItem { */ public static function validateMaxFilesize($element, FormStateInterface $form_state) { if (!empty($element['#value']) && !is_numeric(Bytes::toInt($element['#value']))) { - form_error($element, $form_state, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); + $form_state->setError($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title'])))); } } diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php index 1a14cc22e11..ba578f7d42f 100644 --- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php @@ -371,7 +371,7 @@ class ImageItem extends FileItem { if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) { foreach (array('x', 'y') as $dimension) { if (!$element[$dimension]['#value']) { - form_error($element[$dimension], $form_state, t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title']))); + $form_state->setError($element[$dimension], t('Both a height and width value must be specified in the !name field.', array('!name' => $element['#title']))); return; } } diff --git a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php index 6f6a6296684..52e6eddbbdb 100644 --- a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php +++ b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php @@ -71,7 +71,6 @@ class DataFieldRow extends RowPluginBase { return $options; } - /** * Overrides \Drupal\views\Plugin\views\row\RowPluginBase::buildOptionsForm(). */ @@ -114,7 +113,7 @@ class DataFieldRow extends RowPluginBase { */ public function validateAliasName($element, FormStateInterface $form_state) { if (preg_match('@[^A-Za-z0-9_-]+@', $element['#value'])) { - form_error($element, $form_state, t('The machine-readable name must contain only letters, numbers, dashes and underscores.')); + $form_state->setError($element, t('The machine-readable name must contain only letters, numbers, dashes and underscores.')); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php index dab4ac6164a..293e3209930 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestLimitValidationErrorsForm.php @@ -90,7 +90,7 @@ class FormTestLimitValidationErrorsForm extends FormBase { */ public function elementValidateLimitValidationErrors($element, FormStateInterface $form_state) { if ($element['#value'] == 'invalid') { - form_error($element, $form_state, t('@label element is invalid', array('@label' => $element['#title']))); + $form_state->setError($element, t('@label element is invalid', array('@label' => $element['#title']))); } } diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php index 40803de7e0f..64719e20c29 100644 --- a/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php +++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestValidateRequiredForm.php @@ -79,7 +79,7 @@ class FormTestValidateRequiredForm extends FormBase { public function elementValidateRequired($element, FormStateInterface $form_state) { // Set a custom validation error on the #required element. if (!empty($element['#required_but_empty']) && isset($element['#form_test_required_error'])) { - form_error($element, $form_state, $element['#form_test_required_error']); + $form_state->setError($element, $element['#form_test_required_error']); } } diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php index 39da1700206..439c8e606b4 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -322,7 +322,7 @@ class TaxonomyIndexTid extends ManyToOne { } if ($missing && !empty($this->options['error_message'])) { - form_error($form, $form_state, format_plural(count($missing), 'Unable to find term: @terms', 'Unable to find terms: @terms', array('@terms' => implode(', ', array_keys($missing))))); + $form_state->setError($form, format_plural(count($missing), 'Unable to find term: @terms', 'Unable to find terms: @terms', array('@terms' => implode(', ', array_keys($missing))))); } elseif ($missing && empty($this->options['error_message'])) { $tids = array(0); diff --git a/core/modules/user/src/Plugin/views/access/Role.php b/core/modules/user/src/Plugin/views/access/Role.php index 7008b902177..25bfb908069 100644 --- a/core/modules/user/src/Plugin/views/access/Role.php +++ b/core/modules/user/src/Plugin/views/access/Role.php @@ -86,7 +86,7 @@ class Role extends AccessPluginBase { $role = array_filter($role); if (!$role) { - form_error($form['role'], $form_state, t('You must select at least one role if type is "by role"')); + $form_state->setError($form['role'], t('You must select at least one role if type is "by role"')); } $form_state->setValue(array('access_options', 'role'), $role); diff --git a/core/modules/user/src/Plugin/views/filter/Name.php b/core/modules/user/src/Plugin/views/filter/Name.php index c32abe12b24..391f2383c8f 100644 --- a/core/modules/user/src/Plugin/views/filter/Name.php +++ b/core/modules/user/src/Plugin/views/filter/Name.php @@ -135,7 +135,7 @@ class Name extends InOperator { } if ($missing) { - form_error($form, $form_state, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing))))); + $form_state->setError($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing))))); } return $uids; diff --git a/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php b/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php index aa8294ab50c..21523935f45 100644 --- a/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php +++ b/core/modules/views/src/Plugin/entity_reference/selection/ViewsSelection.php @@ -222,7 +222,7 @@ class ViewsSelection implements SelectionInterface { list($view, $display) = explode(':', $element['view_and_display']['#value']); } else { - form_error($element, $form_state, t('The views entity selection mode requires a view.')); + $form_state->setError($element, t('The views entity selection mode requires a view.')); return; } diff --git a/core/modules/views/src/Plugin/views/cache/Time.php b/core/modules/views/src/Plugin/views/cache/Time.php index 5cca1a1fef8..037219cc273 100644 --- a/core/modules/views/src/Plugin/views/cache/Time.php +++ b/core/modules/views/src/Plugin/views/cache/Time.php @@ -129,7 +129,7 @@ class Time extends CachePluginBase { foreach ($custom_fields as $field) { $cache_options = $form_state->getValue('cache_options'); if ($cache_options[$field] == 'custom' && !is_numeric($cache_options[$field . '_custom'])) { - form_error($form[$field .'_custom'], $form_state, t('Custom time values must be numeric.')); + $form_state->setError($form[$field .'_custom'], t('Custom time values must be numeric.')); } } } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 8f20f062b70..22e8d1676f7 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -1871,24 +1871,24 @@ abstract class DisplayPluginBase extends PluginBase { switch ($section) { case 'display_title': if ($form_state->isValueEmpty('display_title')) { - form_error($form['display_title'], $form_state, t('Display title may not be empty.')); + $form_state->setError($form['display_title'], t('Display title may not be empty.')); } break; case 'css_class': $css_class = $form_state->getValue('css_class'); if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) { - form_error($form['css_class'], $form_state, t('CSS classes must be alphanumeric or dashes only.')); + $form_state->setError($form['css_class'], t('CSS classes must be alphanumeric or dashes only.')); } break; case 'display_id': if ($form_state->getValue('display_id')) { if (preg_match('/[^a-z0-9_]/', $form_state->getValue('display_id'))) { - form_error($form['display_id'], $form_state, t('Display name must be letters, numbers, or underscores only.')); + $form_state->setError($form['display_id'], t('Display name must be letters, numbers, or underscores only.')); } foreach ($this->view->displayHandlers as $id => $display) { if ($id != $this->view->current_display && ($form_state->getValue('display_id') == $id || (isset($display->new_id) && $form_state->getValue('display_id') == $display->new_id))) { - form_error($form['display_id'], $form_state, t('Display id should be unique.')); + $form_state->setError($form['display_id'], t('Display id should be unique.')); } } } diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 82166548790..cd06df00551 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -387,19 +387,19 @@ class Page extends PathPluginBase { $path = $this->getOption('path'); $menu_type = $form_state->getValue(array('menu', 'type')); if ($menu_type == 'normal' && strpos($path, '%') !== FALSE) { - form_error($form['menu']['type'], $form_state, t('Views cannot create normal menu items for paths with a % in them.')); + $form_state->setError($form['menu']['type'], t('Views cannot create normal menu items for paths with a % in them.')); } if ($menu_type == 'default tab' || $menu_type == 'tab') { $bits = explode('/', $path); $last = array_pop($bits); if ($last == '%') { - form_error($form['menu']['type'], $form_state, t('A display whose path ends with a % cannot be a tab.')); + $form_state->setError($form['menu']['type'], t('A display whose path ends with a % cannot be a tab.')); } } if ($menu_type != 'none' && $form_state->isValueEmpty(array('menu', 'title'))) { - form_error($form['menu']['title'], $form_state, t('Title is required for this menu type.')); + $form_state->setError($form['menu']['title'], t('Title is required for this menu type.')); } } } diff --git a/core/modules/views/src/Plugin/views/field/Serialized.php b/core/modules/views/src/Plugin/views/field/Serialized.php index c9d0dd2361b..6432c7eb620 100644 --- a/core/modules/views/src/Plugin/views/field/Serialized.php +++ b/core/modules/views/src/Plugin/views/field/Serialized.php @@ -57,7 +57,7 @@ class Serialized extends FieldPluginBase { public function validateOptionsForm(&$form, FormStateInterface $form_state) { // Require a key if the format is key. if ($form_state->getValue(array('options', 'format')) == 'key' && $form_state->getValue(array('options', 'key')) == '') { - form_error($form['key'], $form_state, t('You have to enter a key if you want to display a key of the data.')); + $form_state->setError($form['key'], t('You have to enter a key if you want to display a key of the data.')); } } diff --git a/core/modules/views/src/Plugin/views/filter/Date.php b/core/modules/views/src/Plugin/views/filter/Date.php index aca1508bb21..8f0778a7f63 100644 --- a/core/modules/views/src/Plugin/views/filter/Date.php +++ b/core/modules/views/src/Plugin/views/filter/Date.php @@ -87,17 +87,17 @@ class Date extends Numeric { if ($operators[$operator]['values'] == 1) { $convert = strtotime($value['value']); if (!empty($form['value']) && ($convert == -1 || $convert === FALSE)) { - form_error($form['value'], $form_state, t('Invalid date format.')); + $form_state->setError($form['value'], t('Invalid date format.')); } } elseif ($operators[$operator]['values'] == 2) { $min = strtotime($value['min']); if ($min == -1 || $min === FALSE) { - form_error($form['min'], $form_state, t('Invalid date format.')); + $form_state->setError($form['min'], t('Invalid date format.')); } $max = strtotime($value['max']); if ($max == -1 || $max === FALSE) { - form_error($form['max'], $form_state, t('Invalid date format.')); + $form_state->setError($form['max'], t('Invalid date format.')); } } } @@ -115,14 +115,14 @@ class Date extends Numeric { // Check if the title is defined but value wasn't defined. if (!empty($group['title'])) { if ((!is_array($group['value']) && empty($group['value'])) || (is_array($group['value']) && count(array_filter($group['value'])) == 1)) { - form_error($form['group_info']['group_items'][$id]['value'], $form_state, t('The value is required if title for this item is defined.')); + $form_state->setError($form['group_info']['group_items'][$id]['value'], t('The value is required if title for this item is defined.')); } } // Check if the value is defined but title wasn't defined. if ((!is_array($group['value']) && !empty($group['value'])) || (is_array($group['value']) && count(array_filter($group['value'])) > 1)) { if (empty($group['title'])) { - form_error($form['group_info']['group_items'][$id]['title'], $form_state, t('The title is required if value for this item is defined.')); + $form_state->setError($form['group_info']['group_items'][$id]['title'], t('The title is required if value for this item is defined.')); } } } diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 2df07ed4d4b..aaaede06690 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -620,14 +620,14 @@ abstract class FilterPluginBase extends HandlerBase { public function validateExposeForm($form, FormStateInterface $form_state) { $identifier = $form_state->getValue(array('options', 'expose', 'identifier')); if (empty($identifier)) { - form_error($form['expose']['identifier'], $form_state, t('The identifier is required if the filter is exposed.')); + $form_state->setError($form['expose']['identifier'], t('The identifier is required if the filter is exposed.')); } elseif ($identifier == 'value') { - form_error($form['expose']['identifier'], $form_state, t('This identifier is not allowed.')); + $form_state->setError($form['expose']['identifier'], t('This identifier is not allowed.')); } if (!$this->view->display_handler->isIdentifierUnique($form_state->get('id'), $identifier)) { - form_error($form['expose']['identifier'], $form_state, t('This identifier is used by another handler.')); + $form_state->setError($form['expose']['identifier'], t('This identifier is used by another handler.')); } } @@ -638,15 +638,15 @@ abstract class FilterPluginBase extends HandlerBase { if (!$form_state->isValueEmpty(array('options', 'group_info'))) { $identifier = $form_state->getValue(array('options', 'group_info', 'identifier')); if (empty($identifier)) { - form_error($form['group_info']['identifier'], $form_state, t('The identifier is required if the filter is exposed.')); + $form_state->setError($form['group_info']['identifier'], t('The identifier is required if the filter is exposed.')); } elseif ($identifier == 'value') { - form_error($form['group_info']['identifier'], $form_state, t('This identifier is not allowed.')); + $form_state->setError($form['group_info']['identifier'], t('This identifier is not allowed.')); } if (!$this->view->display_handler->isIdentifierUnique($form_state->get('id'), $identifier)) { - form_error($form['group_info']['identifier'], $form_state, t('This identifier is used by another handler.')); + $form_state->setError($form['group_info']['identifier'], t('This identifier is used by another handler.')); } } @@ -660,8 +660,7 @@ abstract class FilterPluginBase extends HandlerBase { if (!empty($group['title']) && $operators[$group['operator']]['values'] > 0) { if ((!is_array($group['value']) && trim($group['value']) == "") || (is_array($group['value']) && count(array_filter($group['value'], 'static::arrayFilterZero')) == 0)) { - form_error($form['group_info']['group_items'][$id]['value'], $form_state, - t('The value is required if title for this item is defined.')); + $form_state->setError($form['group_info']['group_items'][$id]['value'], t('The value is required if title for this item is defined.')); } } @@ -669,8 +668,7 @@ abstract class FilterPluginBase extends HandlerBase { if ((!is_array($group['value']) && trim($group['value']) != "") || (is_array($group['value']) && count(array_filter($group['value'], 'static::arrayFilterZero')) > 0)) { if (empty($group['title'])) { - form_error($form['group_info']['group_items'][$id]['title'], $form_state, - t('The title is required if value for this item is defined.')); + $form_state->setError($form['group_info']['group_items'][$id]['title'], t('The title is required if value for this item is defined.')); } } } diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php index b995858d3e7..5eefaf1295e 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/display/DisplayTest.php @@ -100,7 +100,7 @@ class DisplayTest extends DisplayPluginBase { switch ($form_state->get('section')) { case 'test_option': if (!trim($form_state->getValue('test_option'))) { - form_error($form['test_option'], $form_state, t('You cannot have an empty option.')); + $form_state->setError($form['test_option'], t('You cannot have an empty option.')); } break; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 8c989b18827..3ba93f53316 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -939,7 +939,7 @@ function views_element_validate_tags($element, FormStateInterface $form_state) { $values = array_map('trim', explode(',', $element['#value'])); foreach ($values as $value) { if (preg_match("/[^a-z_]/", $value)) { - form_error($element, $form_state, t('The query tags may only contain lower-case alphabetical characters and underscores.')); + $form_state->setError($element, t('The query tags may only contain lower-case alphabetical characters and underscores.')); return; } }