Commit ade9d780 authored by alexpott's avatar alexpott

Issue #2828092 by dmsmidt, gaurav.kapoor, s.d.sirois, andrewmacpherson, Gábor...

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
parent aefca7b8
...@@ -53,6 +53,13 @@ public function __construct(TranslationInterface $string_translation, LinkGenera ...@@ -53,6 +53,13 @@ public function __construct(TranslationInterface $string_translation, LinkGenera
* The current state of the form. * The current state of the form.
*/ */
protected function displayErrorMessages(array $form, FormStateInterface $form_state) { 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 = []; $error_links = [];
$errors = $form_state->getErrors(); $errors = $form_state->getErrors();
// Loop through all form errors and check if we need to display a link. // Loop through all form errors and check if we need to display a link.
......
<?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.');
}
}
...@@ -50,6 +50,7 @@ public function testDisplayErrorMessagesInline() { ...@@ -50,6 +50,7 @@ public function testDisplayErrorMessagesInline() {
$form = [ $form = [
'#parents' => [], '#parents' => [],
'#form_id' => 'test_form',
'#array_parents' => [], '#array_parents' => [],
]; ];
$form['test1'] = [ $form['test1'] = [
...@@ -122,6 +123,7 @@ public function testSetElementErrorsFromFormState() { ...@@ -122,6 +123,7 @@ public function testSetElementErrorsFromFormState() {
$form = [ $form = [
'#parents' => [], '#parents' => [],
'#form_id' => 'test_form',
'#array_parents' => [], '#array_parents' => [],
]; ];
$form['test'] = [ $form['test'] = [
...@@ -137,4 +139,37 @@ public function testSetElementErrorsFromFormState() { ...@@ -137,4 +139,37 @@ public function testSetElementErrorsFromFormState() {
$this->assertSame('invalid', $form['test']['#errors']); $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);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment