diff --git a/core/modules/inline_form_errors/src/FormErrorHandler.php b/core/modules/inline_form_errors/src/FormErrorHandler.php index 8e0f1b820c07766b3f3d0da9e2e381e7a1ac336b..2b892e99dd6845521970cf7b106bd2f7b44fa7a7 100644 --- a/core/modules/inline_form_errors/src/FormErrorHandler.php +++ b/core/modules/inline_form_errors/src/FormErrorHandler.php @@ -53,6 +53,13 @@ public function __construct(TranslationInterface $string_translation, LinkGenera * The current state of the form. */ protected function displayErrorMessages(array $form, FormStateInterface $form_state) { + // Use the original error display for Quick Edit forms, because in this case + // the errors are already near the form element. + if ($form['#form_id'] === 'quickedit_field_form') { + parent::displayErrorMessages($form, $form_state); + return; + } + $error_links = []; $errors = $form_state->getErrors(); // Loop through all form errors and check if we need to display a link. diff --git a/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b956cccbd0bdb0b527bf6ad0806a5f13648dac90 --- /dev/null +++ b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php @@ -0,0 +1,92 @@ + 'page', 'name' => 'page'])->save(); + + // Create a user with the permission to use in-place editing. + $permissions = [ + 'access content', + 'create page content', + 'edit any page content', + 'access contextual links', + 'access in-place editing', + ]; + $this->editorUser = $this->drupalCreateUser($permissions); + $this->drupalLogin($this->editorUser); + } + + /** + * Tests that the inline form errors are not visible for Quick Edit forms. + */ + public function testDisabledInlineFormErrors() { + $session = $this->getSession(); + $web_assert = $this->assertSession(); + + // Create a page node. + $node = $this->drupalCreateNode(); + + // Visit the node page. + $this->drupalGet('node/' . $node->id()); + + // Wait until the quick edit link is available. + $web_assert->waitForElement('css', '.quickedit > a'); + + // Activate the quick editing mode. + $session->executeScript("jQuery('article.node').find('.quickedit > a').click()"); + + $web_assert->waitForElement('css', '.quickedit-toolbar'); + + // Clear the title field. Trigger a 'keyup' to be able to save the changes. + $session->executeScript("jQuery('.field--name-title').text('').trigger('keyup')"); + + // Try to save the changes. + $save_button = $web_assert->waitForElement('css', '.action-save.quickedit-button'); + $save_button->click(); + + // Wait until the form submission is complete. + $web_assert->assertWaitOnAjaxRequest(); + + // Assert that no error summary from Inline Form Errors is shown. + $web_assert->elementTextNotContains('css', '.quickedit-validation-errors', '1 error has been found'); + + // Assert that the required title error is shown. + $web_assert->elementTextContains('css', '.quickedit-validation-errors', 'Title field is required.'); + } + +} diff --git a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php index 8053a751d6984904d5e2a66008d179f437114338..acd255ba27157a363a1994773405a13ee57f324e 100644 --- a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php +++ b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php @@ -50,6 +50,7 @@ public function testDisplayErrorMessagesInline() { $form = [ '#parents' => [], + '#form_id' => 'test_form', '#array_parents' => [], ]; $form['test1'] = [ @@ -122,6 +123,7 @@ public function testSetElementErrorsFromFormState() { $form = [ '#parents' => [], + '#form_id' => 'test_form', '#array_parents' => [], ]; $form['test'] = [ @@ -137,4 +139,37 @@ public function testSetElementErrorsFromFormState() { $this->assertSame('invalid', $form['test']['#errors']); } + /** + * Test that Quick Edit forms show non-inline errors. + * + * @covers ::handleFormErrors + * @covers ::displayErrorMessages + */ + public function testDisplayErrorMessagesNotInlineQuickEdit() { + $form_error_handler = $this->getMockBuilder(FormErrorHandler::class) + ->setConstructorArgs([$this->getStringTranslationStub(), $this->getMock(LinkGeneratorInterface::class), $this->getMock(RendererInterface::class)]) + ->setMethods(['drupalSetMessage']) + ->getMock(); + + $form_error_handler->expects($this->at(0)) + ->method('drupalSetMessage') + ->with('invalid', 'error'); + + $form = [ + '#parents' => [], + '#form_id' => 'quickedit_field_form', + '#array_parents' => [], + ]; + $form['test'] = [ + '#type' => 'textfield', + '#title' => 'Test', + '#parents' => ['test'], + '#id' => 'edit-test', + '#array_parents' => ['test'] + ]; + $form_state = new FormState(); + $form_state->setErrorByName('test', 'invalid'); + $form_error_handler->handleFormErrors($form, $form_state); + } + }