Problem/Motivation
Unable to use layout builders "Discard changes" button when the entity 'layout_builder' form mode has validation errors.
The layout builder override form renders the entity form in the 'layout_builder' mode. If a form field is added which has server or client side validation which fails, then the discard button will not work. The discard button should work independently from the rest of the form.
Steps to reproduce
- Create an entity type and enable layout builder on it. Allow entities to customize individual layouts.
- Add a required text field to the entity.
- Add a new form mode to the entity type with machine name 'layout_builder', if it does not exist already.
- Edit the layout_builder form mode for the entity type, and configure the previously created required text field so it is visible on this form mode.
- Save.
- Create and save the entity
- Access the layout builder page for the entity, make changes.
- Try to use the discard button, without adding a value to the required text field.
- You will see: HTML validation errors because the text field is not filled.
Proposed resolution
When using the discard button: You should see: the browser ignores form input and skips to the discard confirmation page.
Remaining tasks
Fix failing tests
Review
Commit
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#26 | interdiff-3165010-23-26.txt | 556 bytes | acbramley |
#26 | 3165010-26.patch | 4.48 KB | acbramley |
|
Comments
Comment #2
dpiUsing limit validation errors on discard button may be a path forward.
Comment #3
tim.plunkettGood catch, let's get some test coverage first.
Comment #4
dpiComment #5
dpiTest + fix.
Used a new file for tests. There are similar test files, but this set of tests don't need all the heavy dependencies of existing tests, including node/views.
Comment #8
dpiNinja fixes
Comment #10
acbramley CreditAttribution: acbramley at PreviousNext commentedBig nit: we don't need the $urlParameters var anymore as it's only used once.
Other than that, can't fault it!
Comment #11
dpiJust the nit
Comment #12
acbramley CreditAttribution: acbramley at PreviousNext commentedNice! Sending to RTBC
Comment #13
larowlanThis looks great, just a couple of observations that may or may not be relevant
we create the form mode and have it in context, but we re-load it back from the repository and save it again - can we set the component before the first save call and avoid the second save as well as the repository load?
Should we also test that we can submit the discard changes form once we arrive here?
Comment #14
dpiThanks @larowlan,
The mode is created, then the display is created. They are different config types. getFormDisplay will create an entity for us, not fetch the mode from previous line.
Feel free to correct me if there's a better way of doing this.
Updated the test to make sure this form submits.
Comment #15
tim.plunkettYou are right that those are two objects. But by using the display repository, there's still a double save.
Adjusting the test to fit with other LB test conventions. These are only stylistic changes.
Comment #20
smustgrave CreditAttribution: smustgrave at Mobomo commentedI have time and can test this today.
Comment #21
smustgrave CreditAttribution: smustgrave at Mobomo commentedFollowing the steps in the description I was able to verify the error
Using patch #15 resolved the issue
Comment #22
quietone CreditAttribution: quietone at PreviousNext commentedThe patch for 9.1 and 10 are both failing tests, setting back to NW.
Comment #23
acbramley CreditAttribution: acbramley at PreviousNext commentedThe 9.1.x failures seem unrelated (and outdated?), I couldn't reproduce the 10.x failure locally even with assertions turned on but probably something with my setup. Comparing to other similar test setups, I think it may be to do with full vs default mode.
Comment #24
DishaKatariya CreditAttribution: DishaKatariya at QED42 for Drupal India Association commentedComment #25
DishaKatariya CreditAttribution: DishaKatariya at QED42 for Drupal India Association commentedComment #26
acbramley CreditAttribution: acbramley at PreviousNext commentedFixed the assertion error by setting a label on the test entity.
Comment #27
darvanenLGTM, kicking off test for 9.4 but not 10.x because HEAD isn't passing right now.
Comment #28
larowlanQueued 10.0.x as HEAD should be fixed now #3298821: Remove test that tests drupal/core-composer-scaffold when it is not allowed is in
Comment #30
alexpottCommitted and pushed db43eba838 to 10.1.x and 668e3a781a to 10.0.x and b84170c86a to 9.5.x and e5c94094be to 9.4.x. Thanks!
Backported to 9.4.x as a non-disruptive bug-fix.
Comment #39
alexpottThis caused a regression on D10 because classy is deprecated there. There's no need for the test to use classy so I changed the default theme.
Comment #40
alexpottI ensured that the test still fails without the fix with stark as the default theme.