diff --git a/core/core.services.yml b/core/core.services.yml index e791572..5ceaccf 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -337,7 +337,6 @@ services: arguments: ['@request_stack', '@url_generator'] form_error_handler: class: Drupal\Core\Form\FormErrorHandler - arguments: ['@string_translation', '@link_generator', '@renderer'] form_cache: class: Drupal\Core\Form\FormCache arguments: ['@app.root', '@keyvalue.expirable', '@module_handler', '@current_user', '@csrf_token', '@logger.channel.form', '@request_stack', '@page_cache_request_policy'] diff --git a/core/lib/Drupal/Core/Form/FormErrorHandler.php b/core/lib/Drupal/Core/Form/FormErrorHandler.php index 8534ba3..cffdb27 100644 --- a/core/lib/Drupal/Core/Form/FormErrorHandler.php +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php @@ -8,44 +8,12 @@ namespace Drupal\Core\Form; use Drupal\Core\Render\Element; -use Drupal\Core\Routing\LinkGeneratorTrait; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\Core\Url; -use Drupal\Core\Utility\LinkGeneratorInterface; /** * Handles form errors. */ class FormErrorHandler implements FormErrorHandlerInterface { - use StringTranslationTrait; - use LinkGeneratorTrait; - - /** - * The renderer service. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * Constructs a new FormErrorHandler. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * The string translation service. - * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator - * The link generation service. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer service. - */ - public function __construct(TranslationInterface $string_translation, LinkGeneratorInterface $link_generator, RendererInterface $renderer) { - $this->stringTranslation = $string_translation; - $this->linkGenerator = $link_generator; - $this->renderer = $renderer; - } - /** * {@inheritdoc} */ diff --git a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php index cd8e3b2..95d69ed 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php @@ -25,30 +25,28 @@ public function testDisplayErrorMessages() { $link_generator->expects($this->any()) ->method('generate') ->willReturnArgument(0); - $renderer = $this->getMock('\Drupal\Core\Render\RendererInterface'); $form_error_handler = $this->getMockBuilder('Drupal\Core\Form\FormErrorHandler') - ->setConstructorArgs([$this->getStringTranslationStub(), $link_generator, $renderer]) ->setMethods(['drupalSetMessage']) ->getMock(); $form_error_handler->expects($this->at(0)) ->method('drupalSetMessage') - ->with('no title given', 'error'); + ->with('invalid', 'error'); $form_error_handler->expects($this->at(1)) ->method('drupalSetMessage') - ->with('element is invisible', 'error'); + ->with('invalid', 'error'); $form_error_handler->expects($this->at(2)) ->method('drupalSetMessage') - ->with('this missing element is invalid', 'error'); + ->with('invalid', 'error'); $form_error_handler->expects($this->at(3)) ->method('drupalSetMessage') - ->with('3 errors have been found: Test 1Test 2 & a halfTest 3', 'error'); - - $renderer->expects($this->any()) - ->method('renderPlain') - ->will($this->returnCallback(function ($render_array) { - return $render_array[0]['#markup'] . '' . implode(array_map('htmlspecialchars', $render_array[1]['#items']), '') . ''; - })); + ->with('no title given', 'error'); + $form_error_handler->expects($this->at(4)) + ->method('drupalSetMessage') + ->with('element is invisible', 'error'); + $form_error_handler->expects($this->at(5)) + ->method('drupalSetMessage') + ->with('this missing element is invalid', 'error'); $form = [ '#parents' => [], @@ -74,13 +72,6 @@ public function testDisplayErrorMessages() { '#id' => 'edit-test3', ], ]; - $form['test4'] = [ - '#type' => 'textfield', - '#title' => 'Test 4', - '#parents' => ['test4'], - '#id' => 'edit-test4', - '#error_no_message' => TRUE, - ]; $form['test5'] = [ '#type' => 'textfield', '#parents' => ['test5'], @@ -96,7 +87,6 @@ public function testDisplayErrorMessages() { $form_state->setErrorByName('test1', 'invalid'); $form_state->setErrorByName('test2', 'invalid'); $form_state->setErrorByName('fieldset][test3', 'invalid'); - $form_state->setErrorByName('test4', 'no error message'); $form_state->setErrorByName('test5', 'no title given'); $form_state->setErrorByName('test6', 'element is invisible'); $form_state->setErrorByName('missing_element', 'this missing element is invalid'); @@ -110,7 +100,6 @@ public function testDisplayErrorMessages() { */ public function testSetElementErrorsFromFormState() { $form_error_handler = $this->getMockBuilder('Drupal\Core\Form\FormErrorHandler') - ->setConstructorArgs([$this->getStringTranslationStub(), $this->getMock('Drupal\Core\Utility\LinkGeneratorInterface'), $this->getMock('\Drupal\Core\Render\RendererInterface')]) ->setMethods(['drupalSetMessage']) ->getMock();