summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-03-14 09:20:01 (GMT)
committerAlex Pott2017-03-14 09:20:01 (GMT)
commitade9d780aedf0c0b1171edbb0341c5835bb41737 (patch)
tree7f2e2a4ef3ffa7e158f96ef7815d10d137663573
parentaefca7b8c6fdc109103f5fdc0e74b114d7c069d4 (diff)
Issue #2828092 by dmsmidt, gaurav.kapoor, s.d.sirois, andrewmacpherson, Gábor Hojtsy, tstoeckler, jules., Wim Leers, SKAUGHT, marcvangend, yoroy, catch: Inline Form Errors not compatible with Quick Edit
-rw-r--r--core/modules/inline_form_errors/src/FormErrorHandler.php7
-rw-r--r--core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php92
-rw-r--r--core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php35
3 files changed, 134 insertions, 0 deletions
diff --git a/core/modules/inline_form_errors/src/FormErrorHandler.php b/core/modules/inline_form_errors/src/FormErrorHandler.php
index 8e0f1b8..2b892e9 100644
--- a/core/modules/inline_form_errors/src/FormErrorHandler.php
+++ b/core/modules/inline_form_errors/src/FormErrorHandler.php
@@ -53,6 +53,13 @@ class FormErrorHandler extends CoreFormErrorHandler {
* 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 0000000..b956ccc
--- /dev/null
+++ b/core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerQuickEditTest.php
@@ -0,0 +1,92 @@
+<?php
+
+namespace Drupal\Tests\inline_form_errors\FunctionalJavascript;
+
+use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\node\Entity\NodeType;
+
+/**
+ * Tests Inline Form Errors compatibility with Quick Edit.
+ *
+ * @group inline_form_errors
+ */
+class FormErrorHandlerQuickEditTest extends JavascriptTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = [
+ 'quickedit',
+ 'node',
+ 'inline_form_errors',
+ ];
+
+ /**
+ * An editor user with permissions to access the in-place editor.
+ *
+ * @var \Drupal\user\UserInterface
+ */
+ protected $editorUser;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ parent::setUp();
+
+ // Create a page node type for testing.
+ NodeType::create(['type' => '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 8053a75..acd255b 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 @@ class FormErrorHandlerTest extends UnitTestCase {
$form = [
'#parents' => [],
+ '#form_id' => 'test_form',
'#array_parents' => [],
];
$form['test1'] = [
@@ -122,6 +123,7 @@ class FormErrorHandlerTest extends UnitTestCase {
$form = [
'#parents' => [],
+ '#form_id' => 'test_form',
'#array_parents' => [],
];
$form['test'] = [
@@ -137,4 +139,37 @@ class FormErrorHandlerTest extends UnitTestCase {
$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);
+ }
+
}