diff --git a/core/lib/Drupal/Core/Form/FormValidator.php b/core/lib/Drupal/Core/Form/FormValidator.php
index d7d70f3503..4f20f6741a 100644
--- a/core/lib/Drupal/Core/Form/FormValidator.php
+++ b/core/lib/Drupal/Core/Form/FormValidator.php
@@ -335,6 +335,9 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
}
if (isset($elements['#options']) && isset($elements['#value'])) {
+ $error_message = 'The submitted value %choice in the %name element is not allowed.';
+ $name = empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'];
+ $message_arguments = ['%name' => $name];
if ($elements['#type'] == 'select') {
$options = OptGroup::flattenOptions($elements['#options']);
}
@@ -345,8 +348,9 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
$value = in_array($elements['#type'], ['checkboxes', 'tableselect']) ? array_keys($elements['#value']) : $elements['#value'];
foreach ($value as $v) {
if (!isset($options[$v])) {
- $form_state->setError($elements, $this->t('An illegal choice has been detected. Please contact the site administrator.'));
- $this->logger->error('Illegal choice %choice in %name element.', ['%choice' => $v, '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']]);
+ $message_arguments = $message_arguments + ['%choice' => $v];
+ $form_state->setError($elements, $this->t($error_message, $message_arguments));
+ $this->logger->error($error_message, $message_arguments);
}
}
}
@@ -364,8 +368,9 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
$form_state->setValueForElement($elements, NULL);
}
elseif (!isset($options[$elements['#value']])) {
- $form_state->setError($elements, $this->t('An illegal choice has been detected. Please contact the site administrator.'));
- $this->logger->error('Illegal choice %choice in %name element.', ['%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']]);
+ $message_arguments = $message_arguments + ['%choice' => $elements['#value']];
+ $form_state->setError($elements, $this->t($error_message, $message_arguments));
+ $this->logger->error($error_message, $message_arguments);
}
}
}
diff --git a/core/modules/block/tests/src/FunctionalJavascript/BlockAddTest.php b/core/modules/block/tests/src/FunctionalJavascript/BlockAddTest.php
index 17e020d8cc..d3d2e444d0 100644
--- a/core/modules/block/tests/src/FunctionalJavascript/BlockAddTest.php
+++ b/core/modules/block/tests/src/FunctionalJavascript/BlockAddTest.php
@@ -44,7 +44,7 @@ public function testBlockAddThemeSelector() {
// Switch to a theme that doesn't contain the region selected above.
$assert_session->selectExists('Theme')->selectOption('stark');
$assert_session->assertWaitOnAjaxRequest();
- $assert_session->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
+ $assert_session->pageTextNotContains('The submitted value Pre-content in the Region element is not allowed.');
$assert_session->optionExists('Region', '- Select -');
}
diff --git a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
index 14b538bd4e..2356510283 100644
--- a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
@@ -165,7 +165,7 @@ public function testCommentFieldCreate() {
$this->drupalGet('admin/config/people/accounts/fields/user.user.field_user_comment/storage');
$this->submitForm($edit, 'Save field settings');
// We should get an error message.
- $this->assertSession()->pageTextContains('An illegal choice has been detected. Please contact the site administrator.');
+ $this->assertSession()->pageTextContains('The submitted value in the Comment type element is not allowed.');
// Create a comment type for users.
$bundle = CommentType::create([
@@ -183,7 +183,7 @@ public function testCommentFieldCreate() {
$this->drupalGet('admin/config/people/accounts/fields/user.user.field_user_comment/storage');
$this->submitForm($edit, 'Save field settings');
// We shouldn't get an error message.
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
+ $this->assertSession()->pageTextNotContains('The submitted value in the Comment type element is not allowed.');
}
/**
diff --git a/core/modules/system/tests/src/Functional/Form/FormTest.php b/core/modules/system/tests/src/Functional/Form/FormTest.php
index 5599bf9dff..d0027d859f 100644
--- a/core/modules/system/tests/src/Functional/Form/FormTest.php
+++ b/core/modules/system/tests/src/Functional/Form/FormTest.php
@@ -143,7 +143,7 @@ public function testRequiredFields() {
}
if ($type == 'select') {
// Select elements are going to have validation errors with empty
- // input, since those are illegal choices. Just make sure the
+ // input, since those are not allowed choices. Just make sure the
// error is not "field is required".
$this->assertTrue((empty($errors[$element]) || strpos('field is required', (string) $errors[$element]) === FALSE), "Optional '$type' field '$element' is not treated as a required element");
}
@@ -886,7 +886,7 @@ public function testInputForgery() {
// an input forgery.
// @see \Drupal\form_test\Form\FormTestInputForgeryForm::postRender
$this->submitForm(['checkboxes[one]' => TRUE, 'checkboxes[two]' => TRUE], 'Submit');
- $this->assertSession()->pageTextContains('An illegal choice has been detected.');
+ $this->assertSession()->pageTextContains('The submitted value FORGERY in the Checkboxes element is not allowed.');
}
/**
diff --git a/core/modules/system/tests/src/Functional/Form/ValidationTest.php b/core/modules/system/tests/src/Functional/Form/ValidationTest.php
index 0738c34b23..328fca30be 100644
--- a/core/modules/system/tests/src/Functional/Form/ValidationTest.php
+++ b/core/modules/system/tests/src/Functional/Form/ValidationTest.php
@@ -234,8 +234,10 @@ public function testCustomRequiredError() {
$this->assertSession()->pageTextNotContains($form[$key]['#title'] . ' field is required.');
$this->assertSession()->pageTextContains((string) $form[$key]['#form_test_required_error']);
}
+ if (isset($form[$key]['#title'])) {
+ $this->assertSession()->pageTextNotContains('The submitted value in the ' . $form[$key]['#title'] . ' element is not allowed.');
+ }
}
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
// Verify that no custom validation error appears with valid values.
$edit = [
@@ -255,8 +257,10 @@ public function testCustomRequiredError() {
$this->assertSession()->pageTextNotContains($form[$key]['#title'] . ' field is required.');
$this->assertSession()->pageTextNotContains((string) $form[$key]['#form_test_required_error']);
}
+ if (isset($form[$key]['#title'])) {
+ $this->assertSession()->pageTextNotContains('The submitted value in the ' . $form[$key]['#title'] . ' element is not allowed.');
+ }
}
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
}
}
diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php
index e4b1b5417d..aa22353f1e 100644
--- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php
@@ -109,7 +109,7 @@ public function testExposedFormRenderCheckboxes() {
// checked.
$this->clickLink('Page 2');
$this->assertSession()->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 1);
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
+ $this->assertSession()->pageTextNotContains('The submitted value in the Type element is not allowed.');
}
/**
@@ -134,7 +134,7 @@ public function testExposedIsAllOfFilter() {
],
'auto_create' => FALSE,
];
- $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
+ $this->createEntityReferenceField('node', 'article', $field_name, 'Reference Field', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
// Add some test nodes.
$this->createNode([
@@ -158,14 +158,14 @@ public function testExposedIsAllOfFilter() {
// All rows are displayed by default on the first page when no options are
// checked.
$this->assertSession()->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 8);
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
+ $this->assertSession()->pageTextNotContains('The submitted value in the Reference Field element is not allowed.');
// Select one option and ensure we still have results.
$tid = $this->terms[0]->id();
$this->submitForm(["tid[$tid]" => $tid], 'Apply');
// Ensure only nodes tagged with $tid are displayed.
$this->assertSession()->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 2);
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
+ $this->assertSession()->pageTextNotContains('The submitted value in the Reference Field element is not allowed.');
}
}
diff --git a/core/modules/views/tests/src/Functional/Plugin/FilterTest.php b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
index b153916439..0f6a158f56 100644
--- a/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
@@ -173,7 +173,7 @@ public function testInOperatorSelectAllOptions() {
$this->drupalGet('admin/structure/views/view/test_filter_in_operator_ui/edit/default');
$this->submitForm([], 'Save');
$this->submitForm([], 'Update preview');
- $this->assertSession()->pageTextNotContains('An illegal choice has been detected.');
+ $this->assertSession()->pageTextNotContains('The submitted value "page" in the Type element is not allowed.');
}
/**
diff --git a/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php b/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php
index eccceecc59..74233ce3e5 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php
@@ -424,7 +424,7 @@ public function providerTestPerformRequiredValidation() {
'#value' => 'baz',
'#multiple' => FALSE,
],
- 'An illegal choice has been detected. Please contact the site administrator.',
+ 'The submitted value baz in the Test element is not allowed.',
TRUE,
],
[
@@ -437,7 +437,7 @@ public function providerTestPerformRequiredValidation() {
'#value' => ['baz'],
'#multiple' => TRUE,
],
- 'An illegal choice has been detected. Please contact the site administrator.',
+ 'The submitted value 0 in the Test element is not allowed.',
TRUE,
],
[
@@ -450,7 +450,7 @@ public function providerTestPerformRequiredValidation() {
'#value' => ['baz'],
'#multiple' => TRUE,
],
- 'An illegal choice has been detected. Please contact the site administrator.',
+ 'The submitted value baz in the Test element is not allowed.',
TRUE,
],
[