diff --git a/core/lib/Drupal/Core/Form/FormErrorHandler.php b/core/lib/Drupal/Core/Form/FormErrorHandler.php index fee0023..385ef62 100644 --- a/core/lib/Drupal/Core/Form/FormErrorHandler.php +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php @@ -85,7 +85,7 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st // We need to pass this through SafeMarkup::escape() so // drupal_set_message() does not encode the links. The element title, // however, can contain HTML so we need to mark it as safe. - $error_links[] = SafeMarkup::escape($this->l(SafeMarkup::set($title), Url::fromRoute('', [], ['fragment' => $form_element['#id'], 'external' => TRUE]))); + $error_links[] = SafeMarkup::escape($this->l(['#markup' => $title], Url::fromRoute('', [], ['fragment' => $form_element['#id'], 'external' => TRUE]))); unset($errors[$name]); } } @@ -99,6 +99,7 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st $message = $this->formatPlural(count($error_links), '1 error has been found: !errors', '@count errors have been found: !errors', [ '!errors' => SafeMarkup::set(implode(', ', $error_links)), ]); + $this->drupalSetMessage($message, 'error'); } } diff --git a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php index 53d7e76..86367ef 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php @@ -7,6 +7,7 @@ namespace Drupal\Tests\Core\Form; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Form\FormState; use Drupal\Tests\UnitTestCase; @@ -24,7 +25,11 @@ public function testDisplayErrorMessages() { $link_generator = $this->getMock('Drupal\Core\Utility\LinkGeneratorInterface'); $link_generator->expects($this->any()) ->method('generate') - ->willReturnArgument(0); + ->willReturnCallback(function (array $build) { + // @todo This should not be necessary after + // https://www.drupal.org/node/2501975 + return SafeMarkup::set($build['#markup']); + }); $form_error_handler = $this->getMockBuilder('Drupal\Core\Form\FormErrorHandler') ->setConstructorArgs([$this->getStringTranslationStub(), $link_generator]) ->setMethods(['drupalSetMessage']) @@ -41,7 +46,7 @@ public function testDisplayErrorMessages() { ->with('this missing element is invalid', 'error'); $form_error_handler->expects($this->at(3)) ->method('drupalSetMessage') - ->with('3 errors have been found: Test 1, Test 2 & a half, Test 3', 'error'); + ->with('3 errors have been found: Test 1, Test 2 & a half, Test 3', 'error'); $form = [ '#parents' => [],