Problem/Motivation
Update entity delete and field delete operation links to use a modal by default, as delete forms are simple confirm forms in 99.99% of all cases (that 0.01% is just so nobody can tell me I forgot anyone :-P). No reason to make the user go to a different page for this.
Proposed resolution
Update all links to the entity delete and field delete confirmation form to use a modal by default.
Remaining tasks
Update delete link on entity edit form.
Update entity operations delete link
Accessiblity review
Review the patch
User interface changes
Clicking on entity delete links on the edit form or delete tab should bring up the confirmation form in a modal.
The scope extended to include field deletion in a modal in comment #133
API changes
None
Data model changes
None

| Comment | File | Size | Author |
|---|---|---|---|
| #168 | 2253257-168-manual-test.diff | 612 bytes | lauriii |
| #166 | 2253257-166-manual-test.diff | 973 bytes | lauriii |
| #165 | Screenshot 2023-05-31 at 10.23.30.png | 165.28 KB | lauriii |
| #164 | delete-modal-ajax-view.png | 129.76 KB | mstrelan |
| #157 | 2253257-11X.patch | 14.45 KB | bnjmnm |
Issue fork drupal-2253257
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2253257-use-a-modal
changes, plain diff MR !3700
Comments
Comment #1
xanoComment #3
xanoComment #4
xanoComment #5
larowlanLooks like the modal title isn't coming through correctly.

I would expect to see the question 'Are you sure you want to delete' etc.
Comment #6
xanoThat is because of #2255369: DialogController does not respect $content['#title'] for the page title. The question doesn't fit the space the modal reserves for the title, though.
Comment #7
tim.plunkettIf you add
Then it will fit just fine.
Comment #8
xanoMany entity delete pages have
<em>in their titles, which isn't properly displayed by the modal, but that's for another issue as well.Comment #10
xano8: drupal_2253257_8.patch queued for re-testing.
Comment #12
xanoRe-roll.
Comment #14
xanoComment #15
tim.plunkettOut of scope for this issue, but it'd be realllly nice if we had a way to just have
'class' => array('use-modal'),and it would expand to all of this.Comment #16
larowlanThere is an issue for that #2170541: Allow dialog ajax definition to be less verbose
Comment #17
xano14: drupal_2253257_14.patch queued for re-testing.
Comment #18
xanoSince we have to use somewhat more verbose code until that other issue is fixed, do we want to postpone this one, or just get it in?
14: drupal_2253257_14.patch queued for re-testing.
Comment #19
xano14: drupal_2253257_14.patch queued for re-testing.
Comment #21
xanoRe-roll.
Comment #22
wiifmSteps to test:
Visit
/admin/structure/types, click delete on the content typesContent type with content:

Issues:
Content type with no content:

Issues:
Comment #23
larowlanComment #24
swentel commentedrerolled - not sure what the best strategy is for the escaped titles.
Comment #25
dawehnerIsn't that the same kind of problem as what got tackled on #2207247: Dialog titles double escaped for views handlers and delete forms ?
Comment #26
swentel commented@dawehner indeed
Comment #27
adci_contributor commentedGuess we should sending it to testbot.
Comment #28
dawehnerThe other one seems to have an okay from nod_, so let's postpone this issue on top of the other one?
Comment #29
mgiffordComment #30
berdirAnd.. its one year later ;)
I've just RTBC'd #2207247: Dialog titles double escaped for views handlers and delete forms as nobody else wanted to do it. Maybe we can try this again for 8.x-1.x. Note that many config delete forms got quite a bit bigger due to config dependency information but I guess this still makes sense.
Comment #33
jhedstromThis is just a re-roll of #24--it doesn't appear to be working though as something must have changed in the past few years. We can also now add javascript tests for this. I came across this issue while working on #2828201: Add a modal form option to the confirm and field entry form action link types.
Comment #34
berdirSee #2488192: Modal/dialog/ajax is using query parameters instead of accept headers, you want data-dialog-type now, no longer the arcane accepts header.
Comment #35
jhedstromThanks @berdir!
This is now working--still probably needs a js test though.
Comment #38
jhedstromFixes the failing tests.
Comment #39
jhedstromThis has the start of a test. See the
@todofor some odd behavior. I'd expect a new page load with a confirmation message on submit. However, the entity does appear to be deleted...Comment #41
jhedstromThat's a failure I haven't come across before:
Current page is "/entity_test/list", but "/checkout/entity_test/list" expected.I would have thought that
$this->assertSession()->addressEquals(Url::fromRoute('entity.entity_test.collection')->toString());would take a subdirectory into account...Comment #42
berdir@jhedstrom: Looks to me like it fails *because* it takes that into account: We actually are on /checkout/entity_test/list and it sees just /entity_test/list but toString() includes the directory. Try '/' . getInternalPath(), or just hardcode it..
Comment #43
jhedstromAh, I was reading that backwards. I made the change suggested in #42, and have also changed to not use the
loadUnchanged(), and instead just manually cleared the cache (there is an@todoon the method that suggests its behavior will change in the future).I am still not sure why the page isn't reloading after clicking on the delete button.
Comment #44
jhedstromI figured out why this appears to be the case. Apparently when using
clickLink, the verbose page visit logging does not take place, so it only appeared there was no page reload when I was looking at the pages generated by the html output printer.Comment #45
jhedstromGiven #44, this removes the
@todoand just checks for the delete message to be present on the page.Comment #47
Munavijayalakshmi commentedRerolled the patch #45.
Comment #48
droplet commentedLove it.
there's a little problem which is similar to this: #2741877: Nested modals don't work: opening a modal from a modal closes the original
We can assign a new selector to avoid this problem. @see #2741877 Comment 3. (also @see #2741877 Comment 12 for my points)
Thanks.
Comment #49
manuel garcia commentedPatch stil applies cleanly, looks great, and it seems to work as advertised (tested it a bit manually).
One small nitpick:
Fixing that on the go with this patch (please don't credit me for this!).
Anything else we need to be doing here?
Comment #50
vijaycs85Loading icon is coming on next line(ref: screenshot). I guess @Manuel Garcia has fixed it in #2830584: Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait
Comment #51
manuel garcia commentedre #50: Yeah that's a css bug in seven, but my fix for it sits on #26 of #2830584: Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait
https://www.drupal.org/files/issues/interdiff_26071.txt
Comment #52
manuel garcia commentedOn admin/structure/block, we use width 700, which works great, and is still responsive friendly.
Can we use the same width here?
Comment #53
yoroy commentedI tried twice on simplytest with the latest patch but did not get a modal when deleting an article. Am I missing something?
Comment #54
vijaycs85yeah, this issue is for config entities. Content entities are in #2254935: Use a modal for content entity form delete links confirmation forms. Updated titles on both issues :)
Comment #57
chr.fritschJust a re-roll
Comment #58
manuel garcia commentedThanks for the rerroll @chr.fritsch
About the issue mentioned around the loading icon on #50 - The fix that was originally part of #2830584: Use modals for creating, updating, and deleting workflows, with a new DialogFormTrait was split off into its own issue, and was already fixed: #2909882: Throbbers showing within dropbuttons jump to next line - We should probably verify it is now working in this situation just in case.
Comment #59
chr.fritschI checked the use-case from @vijaycs85 in #50 and can verify that this issue is already fixed
Comment #60
manuel garcia commentedRe #52:
I have checked in core, and in all places we're using a width of 700:
Only on
\Drupal\off_canvas_test\Controller\TestControllerdo we use a different width (555), but that is only for tests.Can we switch to using width 700?
Comment #61
manuel garcia commentedRe #59 - thanks @chr.fritsch for checking, great to hear that is now fixed :)
Comment #62
chr.fritschSure, I updated the patch
Comment #64
manuel garcia commentedThanks @chr.fritsch - that test failure:
I'm guessing we should also change the width here, sorry forgot to mention earlier. Not entirely sure it's why the test is failing though, so we'll see...
Comment #65
chr.fritschFix tests
Comment #66
k4v commentedFor me, this works on the entity list, but not on the entity edit form...
Ah maybe it works only for admin theme routes?
Comment #67
manuel garcia commentedThanks @chr.fritsch, that was it then :)
@k4v this issue is for the entity operations links only, which in core are only used on the entity list pages (collection routes). It should work anywhere you use this via views as well.
I can find no other issues with the latest patch, so RTBC++
Comment #68
bojanz commentedImplementation looks good to me.
Only nitpick:
It's weird to me to see method calls broken down into multiple lines, especially when the indentation in the first case doesn't even match. Guessing it was done automatically by phpstorm, and then not corrected.
Feel free to ignore this if core is fine with such a style.
Comment #69
manuel garcia commentedGood point @bojanz - I don't believe this is valid?
Comment #70
borisson_Improved the nitpick mentioned in #68.
Comment #71
bojanz commentedGreat!
Comment #72
manuel garcia commentedAwesome thanks all!
@k4v re #66 - I've just realized that we are already working on the entity edit form delete link, see #2254935: Use a modal for content entity form delete links confirmation forms
Comment #73
lauriiiComment #74
andrewmacpherson commentedJust noticed this has RTBC. Some manual a11y testing will be a good idea here, to avoid a serious regression. We're using an existing pattern so hopefully it'll be fine, but I'd like to check everything is wired up correctly here, labels make sense, etc.
Comment #75
vipul tulse commentedComment #76
vipul tulse commentedComment #78
jibranCan someone please move commit credits here from #1842036: [META] Convert all confirm forms to use modal dialog?
Comment #84
jibran@lauriii pointed out in slack that I can do it myself. As the initial version of this patch was posted in #1842036: [META] Convert all confirm forms to use modal dialog so I went ahead added the patch contributors from there to this issue.
Comment #86
andrewmacpherson commentedComment #87
andrewmacpherson commentedNeeded a re-roll after #2935255: Remove all usages of drupal_set_message and drupal_get_messages in core lib.
Comment #89
chr.fritschMoving back to RTBC, because this patch just got rerolls sincs #70 and I changed
EntityListBuilderTestto useWebDriverTestBasenow.Comment #90
tstoecklerThis is still tagged as needing usability and accessibility review, and I don't think that happened since being requested in #74. So ticking back for now, sorry.
Comment #92
chr.fritschoh true, sorry about that.
Comment #98
aaronmchaleNot much activity on this in a while, are people still interested in this? To me it sounds like a good idea.
I'm happy to schedule this in for a UX Call, but we'd want some up-to-date screenshots in the issue summary (there are ones early in the issue but they use old styling).
Issues summary also generally needs an update with more description and using the templates.
Thanks.
Comment #99
vsujeetkumar commentedRe-roll patch given for 9.3.x, Remains Need Work because of #98
Comment #100
vsujeetkumar commentedBoth the patches are same, By mistake added, Please ignore.
Comment #101
vsujeetkumar commentedAdded "$defaultTheme" and "void return typehint for ::setup()" in EntityListBuilderTest file.
Comment #106
tim.plunkettComment #107
hooroomooComment #108
hooroomooComment #109
hooroomooRerolled and updated test in patch in #108
Comment #110
nayana_mvr commentedVerified the patch #108 and tested it on Drupal version 10.1.x. The patch works fine and I have added the before and after screenshots for reference.
Comment #111
sonam.chaturvedi commentedVerified and tested patch #108 on 10.1.x-dev and patch applied cleanly.
Test Result:
1. Links to delete entities via operation links open as a confirmation model with "Delete" and "cancel" buttons - works fine for config entities (content type, menus, taxonomy, custom blocks), terms and node content.
2. When we delete menu link via operation link (/admin/structure/menu/manage/test-menu) then it opens a new page. Expected is that this should open in a modal similar to terms and node.
Please refer attached after screenshot of menu link.
I see title says "config entities" but in #2254935: Use a modal for content entity form delete links confirmation forms it is mentioned that delete entities via operation links irrespective of config or content to be handled in this issue #2253257.
The title of this issue was updated in #54 to use "config entities", which IMO is incorrect. Please correct me if I am missing anything here.
Comment #112
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #113
dpiThere are still many needs tags on this issue.
-
It wasnt clear skimming the issue how I would be able to opt out of this behavior, in case a contrib module or site specific functionality enhanced the delete form with more UI. It wouldn't be ideal if we changed this to a modal making existing UI unusable.
At least, we should describe ways in code to override this in a change notice.
Comment #114
hooroomooScreenshots provided in #110 so removing tag
Comment #116
hooroomooComment #120
tim.plunkettAdding credits for work done on #2254935: Use a modal for content entity form delete links confirmation forms
Comment #121
hooroomooComment #122
smustgrave commentedSo going to give my best accessibility review
Clicking delete content type the modal opens (Assuming the modal has been tested enough it passes)
Focus is on the X button of the modal
Tabbing takes me through all the elements
Focus stays within the modal.
But the modal does not open when deleting a field.
Comment #123
mgiffordLast anyone on the accessibility team gave this a review was when @andrewmacpherson looked at it 5 years ago. His summary at the time was that it needed a manual review when it was good to go.
As he pointed out at the time, this is a pattern we're already using and testing elsewhere.
@smustgrave So with your review of the content type, I assume that there is no problem closing the modal. I can't see there being links or other focusable elements aside from the "Delete" & "Cancel" buttons.
What about your report about the modal not opening when deleting the field. Is that a new issue, or something needs to be fixed & then re-tested here.
Generally this looks good though. Thanks for doing the keyboard-only testing for this.
Comment #124
bnjmnmRe #122
That is not in the scope of this issue. There is a separate issue for that: #2880003: Use modals on the Manage Fields page.
When using this feature on content with translations, there is a contrast issue with the "delete all translations" button. In Claro theme.css loads after button.css, so theme's
.ui-widgetstyling overrides the button.css button's background color but not the text color, so it winds up white text on a light gray background.While this is not due to the changes here, landing this as-is would increase the likelihood of users encountering this accessibility bug. This can probably be best addressed in a followup that postpones this issue, but if there's a good argument for addressing it here that's an option. If the work is done here, the "Needs followup" tag can be removed.
Comment #125
aaronmchaleRe comment #124, I would strongly suggest that we fix that bug first, even if it's not caused by this issue we would be making the user experience worse by committing this without fixing that problem, so I would definitely support postponing this issue on fixing that bug first.
Comment #126
narendrarI tried to reproduce issue mentioned in #124, but it worked well for me.
Please see attached screenshots.
Comment #127
bnjmnmRe #126
I added
testDeleteModal()toDrupal\FunctionalJavascriptTests\Theme\ClaroViewsBulkOperationsTestto confirm that this is happening. Creating that test also exposed the fact that the modal does not work if toolbar isn't present. I suspect this is because the drupal.ajax library is not loaded unless that is the case.The
testDeleteModal()test can probably stick around in some form, be it in this issue or another one, but I could see it changing a bit when it becomes test coverage to confirm functionality instead of its current role as coverage to prove a problem exists.Comment #128
bnjmnmI think the problem can be addressed if core/drupal.dialog is added on page load instead of when the delete button is pressed. When that library is invoked on AJAX request it reloads Claro's theme.css because it is in the definition of a library that is not yet present. That CSS file is appended as the last item in
<head>, and takes precedence over Claro's button styling due to appearing after the button CSS. The asset has a lower weight, but when it's added via AJAX that isn't taken into account.Comment #129
narendrarAddressed feedback raised in #122 and #124.
Comment #130
smustgrave commented#124 mentioned the delete field was out of scope and covered in another ticket. That change should be reverted.
Unless the scope of this issue is being expanded
Comment #131
narendrarAddressed #130.
Comment #132
borisson_The latest change includes things that should not appear in the MR.
Comment #133
bnjmnmRe #130
That's not accurate. When you mentioned "But the modal does not open when deleting a field." I said that was out of scope as deleting a field is not in scope. This whole issue is about creating modals for delete link confirmation forms, it's just specific to content entities, so fields are not included in that scope.
I'm not spotting any of this - could you add some comments on the MR?
****************************************************************************************
This needs an issue summary update, whether or not the scope changes here.
Although it's not the current scope, there may be benefits to including field deletion in this issues scope, and such a change was discussed. Were that to change, the issue summary should be updated and. If that doesn't change, the issue summary should still be updated because the screenshot there is a confirmation modal of a field being deleted, not a content entity. The screenshot is fine if the scope is broadened, but should be replaced if not.
Comment #134
borisson_I clicked on the compare with previous version link, and saw changes in settings.php (https://git.drupalcode.org/project/drupal/-/merge_requests/3700/diffs?di...) I can't see it in https://git.drupalcode.org/project/drupal/-/merge_requests/3700/diffs, so that comment can be scratched.
Comment #135
narendrarUpdated IS. Added note about #133
Comment #136
bnjmnmComment #137
narendrarComment #138
bnjmnmThere needs to be FunctionalJavascript test coverage for both the field and entity delete links. The only thing that resembles that is a test I added to
ClaroViewsBulkOperationsTestto prove that #124 was in fact happening. Much of that can probably be repurposed to create the tests for the two delete modals, but the functionality should get test coverage, that isn't in the tests for a specific theme, and that actually deletes something as part of the tests (the test I wrote is just proving a button looks bad).Comment #140
utkarsh_33 commentedComment #141
utkarsh_33 commentedComment #142
smustgrave commentedOn the one thread
Can that still happen please.
Comment #143
utkarsh_33 commentedComment #144
smustgrave commentedLeft a question about a missing test.
Comment #145
utkarsh_33 commentedComment #146
bnjmnmThis probably shouldn't go in until #3359494: Focus is lost on dialog close if the opener is inside a collapsible element lands, but I don't want to set this to postponed as it's still fine to review this. The one thing a reviewer should note, however, is right now focus will be lost on modal-close if that modal was opened with something inside a dropbutton. That will be fixed by the aforementioned issue.
Comment #147
hooroomooComment #148
minnur commentedThere is a module for this https://www.drupal.org/project/admin_dialogs
Comment #149
utkarsh_33 commentedAddressed all the feedbacks.
Comment #150
bnjmnmLeft feedback in MR of additional things that need doing.
Comment #152
utkarsh_33 commentedAddressed all the feedbacks.
Comment #153
bnjmnmThis seems pretty close. It looks like one of the reviews asked to move the test coverage for content type deletion but it wound up getting removed instead. That should probably get a home somewhere in the test coverage and this might be ready to go after that, but at that point we may have to postpone on #3359494: Focus is lost on dialog close if the opener is inside a collapsible element as I wouldn't want to add all these modals without focus going to somewhere logical when the modal closes.
Speaking of focus management... As long as #3359494 is taken care of then this passes accessibility review. This doesn't introduce anything that hasn't already been vetted in other confirmation dialogs within core, and I put it through additional manual tests to confirm there was no new surface for problems & that the page-titles-now-dialog-titles still make sense.
Comment #154
smustgrave commentedShould this remain in 11.x to be backported?
Comment #155
bnjmnmTechnically yes, good call. I want to do it a little differently because this was started pre-11 and has a bunch of threads.
The MR is against 10.1.x and it can get ugly bumping up an MR against version that didn't exist when the fork was created. Sometimes it's necessary to just start a new MR that wipes out the threads. Fortunately it won't impact the review process as nothing here is fundamentally different in 11.x with the files being changed. If we can delay the 11-ifying until a pretty solid RTBC, the switch is a little more painless
Comment #156
lauriiiI added the content type delete operation test coverage to the node module since it's essentially provided by the node module, and doesn't have a dependency on other modules. I decided to reuse the
\Drupal\Tests\node\FunctionalJavascript\NodeDeleteConfirmTestsince it seems a bit overkill to have a separate test class for node type delete confirmation. Also, the set-up would be nearly identical for these two.I tagged this for needs usability review 5 years ago. We have been running many iterations of user interviews this spring where we have converted existing forms to modal dialogs and the feedback has been positive there. I don't think this needs further investigation so reverting the tag.
Comment #157
bnjmnmHad an 11x branch ready to push but Gitlab does not appear to be working so here's the 11x in classic patch format.
Comment #160
bnjmnmWhen this issue was created, the top movie in the US was "Captain America: The Winter Soldier"
Today we witness "Issue 2253257: Committed to 11.x and cherry-picked to 10.1.x". Stick around after the issue credits for a sneak peek at some character that will appear in the next commit!
Comment #161
andypostWill it have change record or release notes mention?
Comment #163
aaronmchaleThis is a really great UX improvement, it would be nice to highlight this in the release notes.
Well done everyone!
Comment #164
mstrelan commentedThis is really broken on ajax views. Deleting an entity from the second page of the view takes me to the following path:
/admin/content?page=1&ajax_page_state[theme]=claro&ajax_page_state[theme_token]=OUqFxWhAOwXtkRPcSAdL4jbOuw8Cz4O-QlNSqWuM82c&ajax_page_state[libraries]=big_pipe/big_pipe%2Cclaro/drupal.nav-tabs%2Cclaro/global-styling%2Ccontextual/drupal.contextual-links%2Ccontextual/drupal.contextual-toolbar%2Ccore/drupal.active-link%2Ccore/drupal.dropbutton%2Ccore/drupal.tableheader%2Ccore/drupal.tableresponsive%2Ccore/drupal.tableselect%2Ccore/normalize%2Cshortcut/drupal.shortcut%2Csystem/admin%2Csystem/base%2Ctoolbar/toolbar%2Ctoolbar/toolbar.escapeAdmin%2Ctour/tour%2Cuser/drupal.user.icons%2Cviews/views.ajax%2Cviews/views.module.Comment #165
lauriiiI tried enabling ajax views and delete node on the second page and it's working 🤔
Comment #166
lauriii@mstrelan I still can't reproduce the bug you reported :( Could you by any chance try if the regression gets addressed by this diff?
Comment #167
mstrelan commented@lauriii it seems to only happen with big pipe enabled. Full steps to reproduce:
Applying the patch was slightly better, but I was redirected to the front page instead of back to the admin content view.
FWIW I tested first with a custom docker compose setup and again with ddev default config for Drupal 10.
Comment #168
lauriiiI could reproduce the problem you mentioned on #167 with #166 but I still can't reproduce #164.
My hypothesis is that there's something wrong about the libraries on the page. Here's another issue which tries to make loading the libraries more consistent. Could you test if this has any impact on #164?
Comment #169
lauriiiWith the help of #167, I was able to reproduce this now. The bug reported in #164 is not actually caused by this issue but #956186: Allow AJAX to use GET requests. I'm marking this as fixed since that regression is not made better or worse by this issue.
We may still want to commit something along the lines of #168 though because it addresses some dialog styles in Claro.
Comment #170
lauriiiFiled the follow-up issue: #3364088: Ajax state leaking to Views destination paths.