Skip to content
Snippets Groups Projects
Unverified Commit 832592c1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3103812 by raman.b, rromore, tim.plunkett: Layout Builder's...

Issue #3103812 by raman.b, rromore, tim.plunkett: Layout Builder's ConfigureSectionForm forms do not display validation errors on submit
parent 486bab8b
No related branches found
No related tags found
7 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards,!16Draft: Resolve #2081585 "History storage"
......@@ -2,6 +2,7 @@
namespace Drupal\layout_builder\Form;
use Drupal\Component\Utility\Html;
use Drupal\Core\Ajax\AjaxFormHelperTrait;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -132,6 +133,15 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt
];
if ($this->isAjax()) {
$form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
// @todo static::ajaxSubmit() requires data-drupal-selector to be the same
// between the various Ajax requests. A bug in
// \Drupal\Core\Form\FormBuilder prevents that from happening unless
// $form['#id'] is also the same. Normally, #id is set to a unique HTML
// ID via Html::getUniqueId(), but here we bypass that in order to work
// around the data-drupal-selector bug. This is okay so long as we
// assume that this form only ever occurs once on a page. Remove this
// workaround in https://www.drupal.org/node/2897377.
$form['#id'] = Html::getId($form_state->getBuildInfo()['form_id']);
}
$target_highlight_id = $this->isUpdate ? $this->sectionUpdateHighlightId($delta) : $this->sectionAddHighlightId($delta);
$form['#attributes']['data-layout-builder-target-highlight-id'] = $target_highlight_id;
......
......@@ -306,6 +306,21 @@ public function testConfigurableLayoutSections() {
$assert_session->pageTextContains('Default');
$assert_session->linkExists('Add block');
// Ensure validation error is displayed for ConfigureSectionForm.
$assert_session->linkExists('Add section');
$this->clickLink('Add section');
$assert_session->waitForElementVisible('named', ['link', 'Layout plugin (with settings)']);
$this->clickLink('Layout plugin (with settings)');
$this->assertOffCanvasFormAfterWait('layout_builder_configure_section');
$page->fillField('layout_settings[setting_1]', 'Test Validation Error Message');
$page->pressButton('Add section');
$assert_session->waitForElement('css', '.messages--error');
$assert_session->pageTextContains('Validation Error Message');
$page->fillField('layout_settings[setting_1]', 'Setting 1 Value');
$page->pressButton('Add section');
$assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
$assert_session->pageTextContains('Setting 1 Value');
// Configure the existing section.
$assert_session->linkExists('Configure Section 1');
$this->clickLink('Configure Section 1');
......
......@@ -49,6 +49,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
if ($form_state->getValue('setting_1') === 'Test Validation Error Message') {
$form_state->setErrorByName('setting_1', 'Validation Error Message');
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment