diff --git a/core/includes/form.inc b/core/includes/form.inc index d2cfd47..6fb0a94 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -378,7 +378,7 @@ function template_preprocess_form(&$variables) { // The style guide requires a serial comma. $starting_error_links .= ','; } - $message = \Drupal::translation()->formatPlural($error_count, + $message = \Drupal::translation()->formatPlural($error_count, '1 error has been found: !last_error_link.', '@count errors have been found: !starting_error_links and !last_error_link.', [ diff --git a/core/modules/system/src/Tests/Form/ValidationTest.php b/core/modules/system/src/Tests/Form/ValidationTest.php index fb0ac7e..2ad92eb 100644 --- a/core/modules/system/src/Tests/Form/ValidationTest.php +++ b/core/modules/system/src/Tests/Form/ValidationTest.php @@ -292,7 +292,21 @@ protected function assertErrorMessages($messages) { // Gather the element for checking the jump link section. $error_links[] = \Drupal::l($message['title'], Url::fromRoute('', [], ['fragment' => 'edit-' . str_replace('_', '-', $message['key']), 'external' => TRUE])); } - $top_message = \Drupal::translation()->formatPlural(count($error_links), '1 error has been found', '@count errors have been found') . ': ' . implode(', ', $error_links); + $error_count = count($error_links); + $last_error_link = array_pop($error_links); + $starting_error_links = implode(', ', $error_links); + if ($error_count > 2) { + // The style guide requires a serial comma. + $starting_error_links .= ','; + } + $top_message = \Drupal::translation()->formatPlural($error_count, + '1 error has been found: !last_error_link.', + '@count errors have been found: !starting_error_links and !last_error_link.', + [ + '!starting_error_links' => $starting_error_links, + '!last_error_link' => $last_error_link, + ] + ); $this->assertRaw($top_message); $this->assertNoText(t('An illegal choice has been detected. Please contact the site administrator.')); }