diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 42ec8be..3dfd81c 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -49,6 +49,13 @@ protected $configFactory; /** + * The form error handler. + * + * @var \Drupal\Core\Form\FormErrorInterface + */ + protected $errorHandler; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { @@ -214,4 +221,33 @@ protected function container() { return \Drupal::getContainer(); } + /** + * Returns the form error handler. + * + * @return \Drupal\Core\Form\FormErrorInterface + * The form error handler. + */ + protected function errorHandler() { + if (!$this->errorHandler) { + $this->errorHandler = \Drupal::service('form_builder'); + } + return $this->errorHandler; + } + + /** + * Files an error against a form element. + * + * @param string $name + * The name of the form element. + * @param array $form_state + * An associative array containing the current state of the form. + * @param string $message + * (optional) The error message to present to the user. + * + * @see \Drupal\Core\Form\FormErrorInterface::setErrorByName() + */ + protected function setFormError($name, array &$form_state, $message = '') { + $this->errorHandler()->setErrorByName($name, $form_state, $message); + } + } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php index 78aa4e3..35e5cb5 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php @@ -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', $form_state, $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label()))); + $this->setFormError('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', $form_state, $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->url->value))); + $this->setFormError('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); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php index 4d5eeee..445f8ea 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/CategoryAdminForm.php @@ -125,7 +125,7 @@ public function validateForm(array &$form, array &$form_state) { $unique = $this->categoryStorageController->isUnique($title); } if (!$unique) { - form_set_error('title', $form_state, $this->t('A category named %category already exists. Enter a unique title.', array('%category' => $title))); + $this->setFormError('title', $form_state, $this->t('A category named %category already exists. Enter a unique title.', array('%category' => $title))); } } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php index 3a4a131..6f16441 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php @@ -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', $form_state, $this->t('You must either upload a file or enter a URL.')); + $this->setFormError('remote', $form_state, $this->t('You must either upload a file or enter a URL.')); } } diff --git a/core/modules/ban/lib/Drupal/ban/Form/BanAdmin.php b/core/modules/ban/lib/Drupal/ban/Form/BanAdmin.php index f03d292..29ca186 100644 --- a/core/modules/ban/lib/Drupal/ban/Form/BanAdmin.php +++ b/core/modules/ban/lib/Drupal/ban/Form/BanAdmin.php @@ -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', $form_state, $this->t('This IP address is already banned.')); + $this->setFormError('ip', $form_state, $this->t('This IP address is already banned.')); } elseif ($ip == $this->getRequest()->getClientIP()) { - form_set_error('ip', $form_state, $this->t('You may not ban your own IP address.')); + $this->setFormError('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', $form_state, $this->t('Enter a valid IP address.')); + $this->setFormError('ip', $form_state, $this->t('Enter a valid IP address.')); } } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index 8b04b7e..11f34c1 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -237,7 +237,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', $form_state, t('A block with description %name already exists.', array( + $this->setFormError('info', $form_state, $this->t('A block with description %name already exists.', array( '%name' => $form_state['values']['info'] ))); } diff --git a/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php index ddf49b0..6d28e6f 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php @@ -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('', $form_state, $this->t('This book has been modified by another user, the changes could not be saved.')); + $this->setFormError('', $form_state, $this->t('This book has been modified by another user, the changes could not be saved.')); } } diff --git a/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php b/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php index 1bc25a7..499b70e 100644 --- a/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php +++ b/core/modules/book/lib/Drupal/book/Form/BookSettingsForm.php @@ -53,7 +53,7 @@ public function buildForm(array $form, array &$form_state) { public function validateForm(array &$form, array &$form_state) { $child_type = $form_state['values']['book_child_type']; if (empty($form_state['values']['book_allowed_types'][$child_type])) { - form_set_error('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')))); + $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')))); } parent::validateForm($form, $form_state); diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index c31f53e..8f0eba1 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -275,10 +275,10 @@ public function validate(array $form, array &$form_state) { $date = $form_state['values']['date']; if ($date instanceOf DrupalDateTime && $date->hasErrors()) { - form_set_error('date', $form_state, $this->t('You have to specify a valid date.')); + $this->setFormError('date', $form_state, $this->t('You have to specify a valid date.')); } if ($form_state['values']['name'] && !$form_state['values']['is_anonymous'] && !$account) { - form_set_error('name', $form_state, $this->t('You have to specify a valid author.')); + $this->setFormError('name', $form_state, $this->t('You have to specify a valid author.')); } } elseif ($form_state['values']['is_anonymous']) { @@ -288,7 +288,7 @@ public function validate(array $form, array &$form_state) { if ($form_state['values']['name']) { $accounts = $this->entityManager->getStorageController('user')->loadByProperties(array('name' => $form_state['values']['name'])); if (!empty($accounts)) { - form_set_error('name', $form_state, $this->t('The name you used belongs to a registered user.')); + $this->setFormError('name', $form_state, $this->t('The name you used belongs to a registered user.')); } } } diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigImportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigImportForm.php index be2988e..d8e7be9 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigImportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigImportForm.php @@ -75,7 +75,7 @@ public function buildForm(array $form, array &$form_state) { */ public function validateForm(array &$form, array &$form_state) { if (!empty($_FILES['files']['error']['import_tarball'])) { - form_set_error('import_tarball', $form_state, $this->t('The import tarball could not be uploaded.')); + $this->setFormError('import_tarball', $form_state, $this->t('The import tarball could not be uploaded.')); } else { $form_state['values']['import_tarball'] = $_FILES['files']['tmp_name']['import_tarball']; @@ -99,7 +99,7 @@ public function submitForm(array &$form, array &$form_state) { $form_state['redirect_route']['route_name'] = 'config.sync'; } catch (\Exception $e) { - form_set_error('import_tarball', $form_state, $this->t('Could not extract the contents of the tar file. The error message is @message', array('@message' => $e->getMessage()))); + $this->setFormError('import_tarball', $form_state, $this->t('Could not extract the contents of the tar file. The error message is @message', array('@message' => $e->getMessage()))); } drupal_unlink($path); } diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php b/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php index 24913c7..edddce3 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSingleImportForm.php @@ -183,7 +183,7 @@ public function validateForm(array &$form, array &$form_state) { $entity_storage = $this->entityManager->getStorageController($form_state['values']['config_type']); // If an entity ID was not specified, set an error. if (!isset($data[$id_key])) { - form_set_error('import', $form_state, $this->t('Missing ID key "@id_key" for this @entity_type import.', array('@id_key' => $id_key, '@entity_type' => $definition['label']))); + $this->setFormError('import', $form_state, $this->t('Missing ID key "@id_key" for this @entity_type import.', array('@id_key' => $id_key, '@entity_type' => $definition['label']))); return; } $uuid_key = $definition['entity_keys']['uuid']; @@ -191,17 +191,17 @@ public function validateForm(array &$form, array &$form_state) { if ($entity = $entity_storage->load($data[$id_key])) { $this->configExists = $entity; if (!isset($data[$uuid_key])) { - form_set_error('import', $form_state, $this->t('An entity with this machine name already exists but the import did not specify a UUID.')); + $this->setFormError('import', $form_state, $this->t('An entity with this machine name already exists but the import did not specify a UUID.')); return; } if ($data[$uuid_key] !== $entity->uuid()) { - form_set_error('import', $form_state, $this->t('An entity with this machine name already exists but the UUID does not match.')); + $this->setFormError('import', $form_state, $this->t('An entity with this machine name already exists but the UUID does not match.')); return; } } // If there is no entity with a matching ID, check for a UUID match. elseif (isset($data[$uuid_key]) && $entity_storage->loadByProperties(array($uuid_key => $data[$uuid_key]))) { - form_set_error('import', $form_state, $this->t('An entity with this UUID already exists but the machine name does not match.')); + $this->setFormError('import', $form_state, $this->t('An entity with this UUID already exists but the machine name does not match.')); } } else { diff --git a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php index d1eb9b4..15c7c5d 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php @@ -84,7 +84,7 @@ public function validate(array $form, array &$form_state) { foreach ($recipients as &$recipient) { $recipient = trim($recipient); if (!valid_email_address($recipient)) { - form_set_error('recipients', $form_state, t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient))); + $this->setFormError('recipients', $form_state, $this->t('%recipient is an invalid e-mail address.', array('%recipient' => $recipient))); } } $form_state['values']['recipients'] = $recipients; diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php index b193e25..ca558d6 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -7,19 +7,18 @@ namespace Drupal\edit\Form; +use Drupal\Core\Form\FormBase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Form\FormInterface; use Drupal\user\TempStoreFactory; use Drupal\Core\Entity\EntityChangedInterface; /** * Builds and process a form for editing a single entity field. */ -class EditFieldForm implements FormInterface, ContainerInjectionInterface { +class EditFieldForm extends FormBase { /** * Stores the tempstore factory. @@ -145,7 +144,7 @@ public function validateForm(array &$form, array &$form_state) { if ($changed_field_name = $this->getChangedFieldName($entity)) { $changed_field_errors = $entity->$changed_field_name->validate(); if (count($changed_field_errors)) { - form_set_error('changed_field', $form_state, $changed_field_errors[0]->getMessage()); + $this->setFormError('changed_field', $form_state, $changed_field_errors[0]->getMessage()); } } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index b139bb2..c049666 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -315,12 +315,12 @@ protected function validateAddNew(array $form, array &$form_state) { if (array_filter(array($field['label'], $field['field_name'], $field['type']))) { // Missing label. if (!$field['label']) { - form_set_error('fields][_add_new_field][label', $form_state, $this->t('Add new field: you need to provide a label.')); + $this->setFormError('fields][_add_new_field][label', $form_state, $this->t('Add new field: you need to provide a label.')); } // Missing field name. if (!$field['field_name']) { - form_set_error('fields][_add_new_field][field_name', $form_state, $this->t('Add new field: you need to provide a field name.')); + $this->setFormError('fields][_add_new_field][field_name', $form_state, $this->t('Add new field: you need to provide a field name.')); } // Field name validation. else { @@ -333,7 +333,7 @@ protected function validateAddNew(array $form, array &$form_state) { // Missing field type. if (!$field['type']) { - form_set_error('fields][_add_new_field][type', $form_state, $this->t('Add new field: you need to select a field type.')); + $this->setFormError('fields][_add_new_field][type', $form_state, $this->t('Add new field: you need to select a field type.')); } } } @@ -359,12 +359,12 @@ protected function validateAddExisting(array $form, array &$form_state) { if (array_filter(array($field['label'], $field['field_name']))) { // Missing label. if (!$field['label']) { - form_set_error('fields][_add_existing_field][label', $form_state, $this->t('Re-use existing field: you need to provide a label.')); + $this->setFormError('fields][_add_existing_field][label', $form_state, $this->t('Re-use existing field: you need to provide a label.')); } // Missing existing field name. if (!$field['field_name']) { - form_set_error('fields][_add_existing_field][field_name', $form_state, $this->t('Re-use existing field: you need to select a field.')); + $this->setFormError('fields][_add_existing_field][field_name', $form_state, $this->t('Re-use existing field: you need to select a field.')); } } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 5551232..5110cb7 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -172,7 +172,7 @@ public function validateForm(array &$form, array &$form_state) { $cardinality = $form_state['values']['field']['cardinality']; $cardinality_number = $form_state['values']['field']['cardinality_number']; if ($cardinality === 'number' && empty($cardinality_number)) { - form_error($form['field']['cardinality_container']['cardinality_number'], $form_state, $this->t('Number of values is required.')); + $this->setFormError('field][cardinality_number', $form_state, $this->t('Number of values is required.')); } } diff --git a/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php b/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php index 002c1d5..5ca05c2 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php +++ b/core/modules/filter/lib/Drupal/filter/FilterFormatFormControllerBase.php @@ -232,7 +232,7 @@ public function validate(array $form, array &$form_state) { ->condition('name', $format_name) ->execute(); if ($format_exists) { - form_set_error('name', $form_state, t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name))); + $this->setFormError('name', $form_state, $this->t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name))); } } diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php index 2d1af48..c00b009 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleEditForm.php @@ -156,7 +156,7 @@ public function form(array $form, array &$form_state) { */ public function effectValidate($form, &$form_state) { if (!$form_state['values']['new']) { - form_error($form['effects']['new']['new'], $form_state, $this->t('Select an effect to add.')); + $this->setFormError('new', $form_state, $this->t('Select an effect to add.')); } } diff --git a/core/modules/language/lib/Drupal/language/Form/LanguageAddForm.php b/core/modules/language/lib/Drupal/language/Form/LanguageAddForm.php index 64f3f97..bca5523 100644 --- a/core/modules/language/lib/Drupal/language/Form/LanguageAddForm.php +++ b/core/modules/language/lib/Drupal/language/Form/LanguageAddForm.php @@ -124,11 +124,11 @@ public function validateCustom(array $form, array &$form_state) { $this->validateCommon($form['custom_language'], $form_state); if ($language = language_load($langcode)) { - form_error($form['custom_language']['langcode'], $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); + $this->setFormError('langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); } } else { - form_error($form['predefined_langcode'], $form_state, $this->t('Use the Add language button to save a predefined language.')); + $this->setFormError('predefined_langcode', $form_state, $this->t('Use the Add language button to save a predefined language.')); } } @@ -138,11 +138,11 @@ public function validateCustom(array $form, array &$form_state) { public function validatePredefined($form, &$form_state) { $langcode = $form_state['values']['predefined_langcode']; if ($langcode == 'custom') { - form_error($form['predefined_langcode'], $form_state, $this->t('Fill in the language details and save the language with Add custom language.')); + $this->setFormError('predefined_langcode', $form_state, $this->t('Fill in the language details and save the language with Add custom language.')); } else { if ($language = language_load($langcode)) { - form_error($form['predefined_langcode'], $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); + $this->setFormError('predefined_langcode', $form_state, $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); } } } diff --git a/core/modules/language/lib/Drupal/language/Form/LanguageFormBase.php b/core/modules/language/lib/Drupal/language/Form/LanguageFormBase.php index 2b20c8d..b2adf0a 100644 --- a/core/modules/language/lib/Drupal/language/Form/LanguageFormBase.php +++ b/core/modules/language/lib/Drupal/language/Form/LanguageFormBase.php @@ -70,10 +70,10 @@ public function commonForm(array &$form) { public function validateCommon(array $form, array &$form_state) { // Ensure sane field values for langcode and name. if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state['values']['langcode'])) { - form_error($form['langcode'], $form_state, $this->t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title']))); + $this->setFormError('langcode', $form_state, $this->t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title']))); } if ($form_state['values']['name'] != check_plain($form_state['values']['name'])) { - form_error($form['name'], $form_state, $this->t('%field cannot contain any markup.', array('%field' => $form['name']['#title']))); + $this->setFormError('name', $form_state, $this->t('%field cannot contain any markup.', array('%field' => $form['name']['#title']))); } } diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php index 4a8ec2d..2271b14 100644 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php @@ -143,10 +143,10 @@ public function validateForm(array &$form, array &$form_state) { foreach ($mappings as $key => $data) { // Make sure browser_langcode is unique. if (array_key_exists($data['browser_langcode'], $unique_values)) { - form_set_error('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes must be unique.')); + $this->setFormError('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes must be unique.')); } elseif (preg_match('/[^a-z\-]/', $data['browser_langcode'])) { - form_set_error('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes can only contain lowercase letters and a hyphen(-).')); + $this->setFormError('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes can only contain lowercase letters and a hyphen(-).')); } $unique_values[$data['browser_langcode']] = $data['drupal_langcode']; } @@ -157,10 +157,10 @@ public function validateForm(array &$form, array &$form_state) { if (!empty($data['browser_langcode'])) { // Make sure browser_langcode is unique. if (array_key_exists($data['browser_langcode'], $unique_values)) { - form_set_error('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes must be unique.')); + $this->setFormError('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes must be unique.')); } elseif (preg_match('/[^a-z\-]/', $data['browser_langcode'])) { - form_set_error('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes can only contain lowercase letters and a hyphen(-).')); + $this->setFormError('mappings][' . $key . '][browser_langcode', $form_state, $this->t('Browser language codes can only contain lowercase letters and a hyphen(-).')); } $unique_values[$data['browser_langcode']] = $data['drupal_langcode']; } diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php index 9a6c267..ac709e3 100644 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationUrlForm.php @@ -106,18 +106,18 @@ public function validateForm(array &$form, array &$form_state) { if (!$language->default && $form_state['values']['language_negotiation_url_part'] == LANGUAGE_NEGOTIATION_URL_PREFIX) { // Throw a form error if the prefix is blank for a non-default language, // although it is required for selected negotiation type. - form_error($form['prefix'][$langcode], $form_state, t('The prefix may only be left blank for the default language.')); + $this->setFormError("prefix][$langcode", $form_state, t('The prefix may only be left blank for the default language.')); } } elseif (strpos($value, '/') !== FALSE) { // Throw a form error if the string contains a slash, // which would not work. - form_error($form['prefix'][$langcode], $form_state, t('The prefix may not contain a slash.')); + $this->setFormError("prefix][$langcode", $form_state, t('The prefix may not contain a slash.')); } elseif (isset($count[$value]) && $count[$value] > 1) { // Throw a form error if there are two languages with the same // domain/prefix. - form_error($form['prefix'][$langcode], $form_state, t('The prefix for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); + $this->setFormError("prefix][$langcode", $form_state, t('The prefix for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); } } @@ -130,13 +130,13 @@ public function validateForm(array &$form, array &$form_state) { if (!$language->default && $form_state['values']['language_negotiation_url_part'] == LANGUAGE_NEGOTIATION_URL_DOMAIN) { // Throw a form error if the domain is blank for a non-default language, // although it is required for selected negotiation type. - form_error($form['domain'][$langcode], $form_state, t('The domain may only be left blank for the default language.')); + $this->setFormError("domain][$langcode", $form_state, t('The domain may only be left blank for the default language.')); } } elseif (isset($count[$value]) && $count[$value] > 1) { // Throw a form error if there are two languages with the same // domain/domain. - form_error($form['domain'][$langcode], $form_state, t('The domain for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); + $this->setFormError("domain][$langcode", $form_state, t('The domain for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); } } @@ -147,7 +147,7 @@ public function validateForm(array &$form, array &$form_state) { // Ensure we have exactly one protocol when checking the hostname. $host = 'http://' . str_replace(array('http://', 'https://'), '', $value); if (parse_url($host, PHP_URL_HOST) != $value) { - form_error($form['domain'][$langcode], $form_state, t('The domain for %language may only contain the domain name, not a protocol and/or port.', array('%language' => $name))); + $this->setFormError("domain][$langcode", $form_state, t('The domain for %language may only contain the domain name, not a protocol and/or port.', array('%language' => $name))); } } } diff --git a/core/modules/locale/lib/Drupal/locale/Form/LocaleSettingsForm.php b/core/modules/locale/lib/Drupal/locale/Form/LocaleSettingsForm.php index 3d4a410..630b716 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/LocaleSettingsForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/LocaleSettingsForm.php @@ -93,7 +93,7 @@ public function validateForm(array &$form, array &$form_state) { parent::validateForm($form, $form_state); if (empty($form['#translation_directory']) && $form_state['values']['use_source'] == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) { - form_set_error('use_source', $form_state, t('You have selected local translation source, but no Interface translation directory was configured.', array('@url' => url('admin/config/media/file-system')))); + $this->setFormError('use_source', $form_state, $this->t('You have selected local translation source, but no Interface translation directory was configured.', array('@url' => url('admin/config/media/file-system')))); } } diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php index 24456a8..34c93be 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php @@ -166,8 +166,8 @@ public function validateForm(array &$form, array &$form_state) { foreach ($form_state['values']['strings'] as $lid => $translations) { foreach ($translations['translations'] as $key => $value) { if (!locale_string_is_safe($value)) { - form_set_error("strings][$lid][translations][$key", $form_state, $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); - form_set_error("translations][$langcode][$key", $form_state, $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); + $this->setFormError("strings][$lid][translations][$key", $form_state, $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); + $this->setFormError("translations][$langcode][$key", $form_state, $this->t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING); } } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php index 7c39219..bc2c71d 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -234,7 +234,7 @@ public function validate(array $form, array &$form_state) { } } if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) { - form_set_error('link_path', $form_state, t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path))); + $this->setFormError('link_path', $form_state, $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path))); } parent::validate($form, $form_state); diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 1153188..e37eb41 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -318,7 +318,7 @@ public function validate(array $form, array &$form_state) { $node = $this->buildEntity($form, $form_state); if ($node->id() && (node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime())) { - form_set_error('changed', $form_state, t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.')); + $this->setFormError('changed', $form_state, $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.')); } // Validate the "authored by" field. @@ -326,14 +326,14 @@ public function validate(array $form, array &$form_state) { // The use of empty() is mandatory in the context of usernames // as the empty string denotes the anonymous user. In case we // are dealing with an anonymous user we set the user ID to 0. - form_set_error('name', $form_state, t('The username %name does not exist.', array('%name' => $form_state['values']['name']))); + $this->setFormError('name', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['name']))); } // Validate the "authored on" field. // The date element contains the date object. $date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date); if ($date->hasErrors()) { - form_set_error('date', $form_state, t('You have to specify a valid date.')); + $this->setFormError('date', $form_state, $this->t('You have to specify a valid date.')); } // Invoke hook_node_validate() for validation needed by modules. diff --git a/core/modules/node/lib/Drupal/node/NodeTypeFormController.php b/core/modules/node/lib/Drupal/node/NodeTypeFormController.php index f48b591..6d7d7b0 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeFormController.php @@ -182,7 +182,7 @@ public function validate(array $form, array &$form_state) { $id = trim($form_state['values']['type']); // '0' is invalid, since elsewhere we check it using empty(). if ($id == '0') { - form_set_error('type', $form_state, t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id))); + $this->setFormError('type', $form_state, $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id))); } } diff --git a/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php b/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php index 121f6a7..1e4b106 100644 --- a/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php +++ b/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php @@ -126,7 +126,7 @@ public function validate(array $form, array &$form_state) { } // Make sure at least one mapping is defined. elseif (!$picture_mapping->isNew() && !$picture_mapping->hasMappings()) { - form_set_error('mappings', $form_state, $this->t('Please select at least one mapping.')); + $this->setFormError('mappings', $form_state, $this->t('Please select at least one mapping.')); } } } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php index bb4c9f7..eadc2dd 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchBlockForm.php @@ -58,7 +58,7 @@ public function submitForm(array &$form, array &$form_state) { // "field is required" because the search keywords field has no title. // The error message would also complain about a missing #title field.) if ($form_state['values']['search_block_form'] == '') { - form_set_error('keys', $form_state, $this->t('Please enter some keywords.')); + $this->setFormError('keys', $form_state, $this->t('Please enter some keywords.')); } $form_id = $form['form_id']['#value']; @@ -72,7 +72,7 @@ public function submitForm(array &$form, array &$form_state) { ); } else { - form_set_error(NULL, $form_state, $this->t('Search is currently disabled.'), 'error'); + $this->setFormError(NULL, $form_state, $this->t('Search is currently disabled.'), 'error'); } } } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchForm.php b/core/modules/search/lib/Drupal/search/Form/SearchForm.php index 69022dd..fe49f16 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchForm.php @@ -112,7 +112,7 @@ public function validateForm(array &$form, array &$form_state) { public function submitForm(array &$form, array &$form_state) { $keys = $form_state['values']['processed_keys']; if ($keys == '') { - form_set_error('keys', $form_state, t('Please enter some keywords.')); + $this->setFormError('keys', $form_state, $this->t('Please enter some keywords.')); // Fall through to the form redirect. } diff --git a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php index 0ceef4b..41b92af 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php @@ -218,7 +218,7 @@ public function validateForm(array &$form, array &$form_state) { $new_plugins = array_filter($form_state['values']['active_plugins']); $default = $form_state['values']['default_plugin']; if (!in_array($default, $new_plugins, TRUE)) { - form_set_error('default_plugin', $form_state, $this->t('Your default search plugin is not selected as an active plugin.')); + $this->setFormError('default_plugin', $form_state, $this->t('Your default search plugin is not selected as an active plugin.')); } } // Handle per-plugin validation logic. diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php index 461f1b4..404dd1d 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutSetFormController.php @@ -65,7 +65,7 @@ public function validate(array $form, array &$form_state) { $entity = $this->entity; // Check to prevent a duplicate title. if ($form_state['values']['label'] != $entity->label() && shortcut_set_title_exists($form_state['values']['label'])) { - form_set_error('label', $form_state, t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label']))); + $this->setFormError('label', $form_state, $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label']))); } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php b/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php index f54dd6c..24bdb85 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestSettingsForm.php @@ -97,7 +97,7 @@ public function validateForm(array &$form, array &$form_state) { // If a password was provided but a username wasn't, the credentials are // incorrect, so throw an error. if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) { - form_set_error('simpletest_httpauth_username', $form_state, $this->t('HTTP authentication credentials must include a username in addition to a password.')); + $this->setFormError('simpletest_httpauth_username', $form_state, $this->t('HTTP authentication credentials must include a username in addition to a password.')); } parent::validateForm($form, $form_state); diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php b/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php index d8a69b5..bdce06b 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatFormBase.php @@ -191,7 +191,7 @@ public function validate(array $form, array &$form_state) { $pattern = trim($form_state['values']['date_format_pattern']); foreach ($this->dateFormatStorage->loadMultiple() as $format) { if ($format->getPattern() == $pattern && ($this->entity->isNew() || $format->id() != $this->entity->id())) { - form_set_error('date_format_pattern', $form_state, t('This format already exists. Enter a unique format string.')); + $this->setFormError('date_format_pattern', $form_state, $this->t('This format already exists. Enter a unique format string.')); continue; } } diff --git a/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php index fdc180c..34e3584 100644 --- a/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php +++ b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php @@ -144,7 +144,7 @@ public function validateForm(array &$form, array &$form_state) { } // Validate front page path. if (!drupal_valid_path($form_state['values']['site_frontpage'])) { - form_set_error('site_frontpage', $form_state, t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); + $this->setFormError('site_frontpage', $form_state, $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_frontpage']))); } // Get the normal paths of both error pages. if (!empty($form_state['values']['site_403'])) { @@ -155,11 +155,11 @@ public function validateForm(array &$form, array &$form_state) { } // Validate 403 error path. if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { - form_set_error('site_403', $form_state, t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); + $this->setFormError('site_403', $form_state, $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_403']))); } // Validate 404 error path. if (!empty($form_state['values']['site_404']) && !drupal_valid_path($form_state['values']['site_404'])) { - form_set_error('site_404', $form_state, t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); + $this->setFormError('site_404', $form_state, $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state['values']['site_404']))); } parent::validateForm($form, $form_state); diff --git a/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php b/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php index 39d0caa..ec76227 100644 --- a/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php @@ -332,7 +332,7 @@ public function validateForm(array &$form, array &$form_state) { } else { // File upload failed. - form_set_error('logo_upload', $form_state, t('The logo could not be uploaded.')); + $this->setFormError('logo_upload', $form_state, $this->t('The logo could not be uploaded.')); } } @@ -348,7 +348,7 @@ public function validateForm(array &$form, array &$form_state) { } else { // File upload failed. - form_set_error('favicon_upload', $form_state, t('The favicon could not be uploaded.')); + $this->setFormError('favicon_upload', $form_state, $this->t('The favicon could not be uploaded.')); } } @@ -357,13 +357,13 @@ public function validateForm(array &$form, array &$form_state) { if ($form_state['values']['logo_path']) { $path = $this->validatePath($form_state['values']['logo_path']); if (!$path) { - form_set_error('logo_path', $form_state, t('The custom logo path is invalid.')); + $this->setFormError('logo_path', $form_state, $this->t('The custom logo path is invalid.')); } } if ($form_state['values']['favicon_path']) { $path = $this->validatePath($form_state['values']['favicon_path']); if (!$path) { - form_set_error('favicon_path', $form_state, t('The custom favicon path is invalid.')); + $this->setFormError('favicon_path', $form_state, $this->t('The custom favicon path is invalid.')); } } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index bbed7fd..925d83c 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -161,7 +161,7 @@ public function validate(array $form, array &$form_state) { // Ensure numeric values. if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) { - form_set_error('weight', $form_state, $this->t('Weight value must be numeric.')); + $this->setFormError('weight', $form_state, $this->t('Weight value must be numeric.')); } } diff --git a/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php b/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php index f72c201..d2d4186 100644 --- a/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php +++ b/core/modules/update/lib/Drupal/update/UpdateSettingsForm.php @@ -90,10 +90,10 @@ public function validateForm(array &$form, array &$form_state) { $form_state['notify_emails'] = $valid; } elseif (count($invalid) == 1) { - form_set_error('update_notify_emails', $form_state, t('%email is not a valid e-mail address.', array('%email' => reset($invalid)))); + $this->setFormError('update_notify_emails', $form_state, $this->t('%email is not a valid e-mail address.', array('%email' => reset($invalid)))); } else { - form_set_error('update_notify_emails', $form_state, t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid)))); + $this->setFormError('update_notify_emails', $form_state, $this->t('%emails are not valid e-mail addresses.', array('%emails' => implode(', ', $invalid)))); } } diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index 1179cdc..4983b0f 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -296,7 +296,7 @@ public function validate(array $form, array &$form_state) { // Validate new or changing username. if (isset($form_state['values']['name'])) { if ($error = user_validate_name($form_state['values']['name'])) { - form_set_error('name', $form_state, $error); + $this->setFormError('name', $form_state, $error); } // Cast the user ID as an integer. It might have been set to NULL, which // could lead to unexpected results. @@ -310,7 +310,7 @@ public function validate(array $form, array &$form_state) { ->fetchField(); if ($name_taken) { - form_set_error('name', $form_state, $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); + $this->setFormError('name', $form_state, $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name']))); } } } @@ -329,10 +329,10 @@ public function validate(array $form, array &$form_state) { if ($mail_taken) { // Format error message dependent on whether the user is logged in or not. if ($GLOBALS['user']->isAuthenticated()) { - form_set_error('mail', $form_state, $this->t('The e-mail address %email is already taken.', array('%email' => $mail))); + $this->setFormError('mail', $form_state, $this->t('The e-mail address %email is already taken.', array('%email' => $mail))); } else { - form_set_error('mail', $form_state, $this->t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $mail, '@password' => url('user/password')))); + $this->setFormError('mail', $form_state, $this->t('The e-mail address %email is already registered. Have you forgotten your password?', array('%email' => $mail, '@password' => url('user/password')))); } } } @@ -347,7 +347,7 @@ public function validate(array $form, array &$form_state) { $user_schema = drupal_get_schema('users'); if (drupal_strlen($form_state['values']['signature']) > $user_schema['fields']['signature']['length']) { - form_set_error('signature', $form_state, $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length']))); + $this->setFormError('signature', $form_state, $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $user_schema['fields']['signature']['length']))); } } } diff --git a/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php b/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php index 4aad0e9..46744a4 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserLoginForm.php @@ -118,7 +118,7 @@ public function submitForm(array &$form, array &$form_state) { public function validateName(array &$form, array &$form_state) { if (!empty($form_state['values']['name']) && user_is_blocked($form_state['values']['name'])) { // Blocked in user administration. - form_set_error('name', $form_state, $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name']))); + $this->setFormError('name', $form_state, $this->t('The username %name has not been activated or is blocked.', array('%name' => $form_state['values']['name']))); } } @@ -186,15 +186,15 @@ public function validateFinal(array &$form, array &$form_state) { if (isset($form_state['flood_control_triggered'])) { if ($form_state['flood_control_triggered'] == 'user') { - form_set_error('name', $form_state, format_plural($flood_config->get('user_limit'), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or request a new password.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.', array('@url' => url('user/password')))); + $this->setFormError('name', $form_state, format_plural($flood_config->get('user_limit'), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or request a new password.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later or request a new password.', array('@url' => url('user/password')))); } else { // We did not find a uid, so the limit is IP-based. - form_set_error('name', $form_state, $this->t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', array('@url' => url('user/password')))); + $this->setFormError('name', $form_state, $this->t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later or request a new password.', array('@url' => url('user/password')))); } } else { - form_set_error('name', $form_state, $this->t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name'])))))); + $this->setFormError('name', $form_state, $this->t('Sorry, unrecognized username or password. Have you forgotten your password?', array('@password' => url('user/password', array('query' => array('name' => $form_state['values']['name'])))))); $accounts = $this->userStorage->loadByProperties(array('name' => $form_state['values']['name'])); if (!empty($accounts)) { watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name'])); diff --git a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php index 2399a58..07d35e9 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php +++ b/core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php @@ -119,7 +119,7 @@ public function validateForm(array &$form, array &$form_state) { form_set_value(array('#parents' => array('account')), $account, $form_state); } else { - form_set_error('name', $form_state, $this->t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); + $this->setFormError('name', $form_state, $this->t('Sorry, %name is not recognized as a username or an e-mail address.', array('%name' => $name))); } } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php index 2c3d19c..f02e145 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewAddFormController.php @@ -171,7 +171,7 @@ public function validate(array $form, array &$form_state) { foreach ($errors as $display_errors) { foreach ($display_errors as $name => $message) { - form_set_error($name, $form_state, $message); + $this->setFormError($name, $form_state, $message); } } } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index f8fd10a..117fa5b 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -236,7 +236,7 @@ public function validate(array $form, array &$form_state) { $view = $this->entity; foreach ($view->getExecutable()->validate() as $display_errors) { foreach ($display_errors as $error) { - form_set_error('', $form_state, $error); + $this->setFormError('', $form_state, $error); } } }