Problem/Motivation
The initial problem is that the File Listing page "Delete" link fails with "Oops, something went wrong. Check your browser's developer console for more details." when language negotiation uses domains.
I selected the "language system" component, but this problem spans subsystems.
Steps to reproduce
- Setup two domains (.ddev/config.yaml additional_hostnames, I used "local" and "es.local").
- Install Drupal, enable media and language modules.
- Add a language for the second domain on admin/config/regional/language (I used Spanish). Configure detection on admin/config/regional/language/detection, edit "URL", select "Domain", and set the two domain URL's (I used local.ddev.site and es.local.ddev.site)
- Add a media document from admin/content/media
- Try to delete the file just added on admin/content/files. You will see the error "Oops, something went wrong. Check your browser's developer console for more details."
Proposed resolution
Fix RedirectDestination::get() method to return only relative paths for destination.
Remove todo for https://www.drupal.org/project/drupal/issues/2980527
Remaining tasks
Why is this solution preferred over #2980527: Domain-based language negotiation strips "destination" URL query argument, causing BigPipe error?
User interface changes
API changes
Data model changes
Release notes snippet
Original proposed resolution
This is a rabbit hole. Working backwards:
ConfirmFormHelper::buildCancelLink() needs a URL. It tries to get it from either the destination parameter or from the entity URL. I think we need to fix both code paths.
Problem #1 - destination
We can't get it from the destination parameter because language negotiation converts the relative URL to a full URL which is then sanitized by RequestSanitizer.
a. Use #2980527: Domain-based language negotiation strips "destination" URL query argument, causing BigPipe error - however once this is applied, we run into Problem #3.
b. See #3424720: LanguageNegotiationUrl unnecessarily adds domain to outbound URL's - Change LanguageNegotiationUrl::outboundUrl() to not set the base_path if it matches the current page's base_path.
Problem #2 - File Entity
If the destination parameter is missing, the URL is retrieved from toUrl() which throws the exception that started this problem. Previous attempts have been made (see [#3371753} and #3421114: [regression] Entity::toUrl() without argument is broken for entity types with a URI callback) to make this not fail, but this still doesn't work for File entities. I can fix my local sites problem with https://drupal.org/project/file_entity which adds the necessary link templates but a contrib solution to a core problem is only an interim fix. We should look there for the minimal required templates to add to core.
Problem #3 - buildCancelLink() external URLs
This code has a rather old comment to "revisit" #2418219: Deprecate destination URLs that don't include the base path. I think that Drupal has moved past this issue, and won't ever revisit it, so IMO we should comment on the issue, and remove the comment.
The try/catch was added in #2512452: Confirm form cancel button can lead to external domain to prevent external URL's, but does not use, and should use, UrlHelper::externalIsLocal() which could now be used.
| Comment | File | Size | Author |
|---|---|---|---|
| #57 | domain-based-language-negotiation-6847.patch | 4.4 KB | charlliequadros |
| #15 | delete-confirm-after-fix.png | 150.3 KB | sukr_s |
| #13 | error-on-delete.png | 303.49 KB | sukr_s |
| #8 | cannot-delete-file-3424701-5.patch | 696 bytes | sukr_s |
Issue fork drupal-3424701
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:
- 11.x
changes, plain diff MR !6847
- 3424701-cannot-delete-file
compare
- 10.2.x
changes, plain diff MR !6848
Comments
Comment #2
douggreen commentedComment #3
douggreen commentedComment #4
douggreen commentedComment #8
sukr_s commentedSupport for delete-form is required. I've tested this and it works fine.
Comment #9
jenlamptonChanging to RTBC after the last comment.
Comment #11
catchIt's not clear to me whether this will fix the original bug report, would be good to add some test coverage if the lack of this is causing user-facing fatal errors. Could also use an issue summary update.
Comment #12
prabuela commentedComment #13
sukr_s commentedComment #14
sukr_s commentedComment #15
sukr_s commented- Issue summary updated. error screenshot added.
- New test case added
- Screenshot post fix added
The MR has failed at test case testUnmanagedGitIgnoreWhenGitNotAvailable which seems unrelated to the code fix. what should be done?
Comment #16
smustgrave commentedAppears to have test failures
Comment #17
sukr_s commentedComment #18
smustgrave commentedIssue summary appears to be updated with solution in #13 so removing that tag
Ran test only feature and got
So removing that tag
Seems additional condition for deletion seems to be there.
Comment #19
catchThis seems like it would come from
lib/Drupal/Core/Entity/EntityListBuilder.phpbut that passes in 'delete-form' to ::toUrl() so it can't be that.I think we need a backtrace here with what is calling ::toUrl() with NULL, and fix it there, or at least understand what's going wrong a bit more. Seems weird to default to deleting just because there's no canonical or edit link. Also the exception message would need to be updated which is not done in the MR.
Comment #20
catchIs it this in the actual delete form?
If so, I think the problem is file module missing a 'collection' link for the cancel link to point to, it shouldn't point to the delete page, that's what we're on.
Comment #21
sukr_s commentedComment #22
sukr_s commented- IS updated
- fix as per #20 done
Comment #23
catchSorry I don't think that fix is right either because views is an optional module and therefore the route may or may not exist.
Couple of questions:
1. What happens if we remove the exception from EntityBase::toUrl() and fall back to
<front>for the route there - I don't think that's the correct fix but I would like to see what happens.2. It would be useful to manually test this in 10.1 or 10.0.x from before the regression was introduced, and see what the cancel button actually did on this form, I have a feeling the button was broken but it rendered and no-one ever noticed.
Comment #24
sukr_s commentedIf the views module does not exist, then this screen is not accessible and therefore it's not possible to reach the error.
I tried to add the collection route conditionally but the REST tests fail.
1. If the exception is commented out, it tries to create URL with entity.file.collection and ends up throwing an exception. If that is commented out too and URL to is created, then the dialog pops up. Click on cancel, it remains on the same page.
2. The problem occurs only when the language module is enabled and multiple languages are configured. If it's a single language site then the functionality works fine. The cancel stays on the same page, which would be the expected behavior. If multiple languages are configured then the delete confirmation popup doesn't open, it ends up with exception.
If the original fix of adding 'delete-form' is enabled then the delete confirmation pops-up and clicking on cancel, it remains on the same page.
Comment #25
smustgrave commentedProposed solution shouldn't point to a comment, for ease of review please update issue summary with actual proposed solution.
Find saying "Go to this link" the same as when people put "see patch"
Comment #26
sukr_s commented@smustgrave the correct solution needs to be confirmed by @catch. once done can update the same
putting it back to NR for @catch attention.
Comment #27
catchI think it would still be possible to browse directly to the URL, and definitely possible to set up an alternative view at a different path to do the same thing (or just change the path on the default view).
I think someone should do this:
Once we know what the original behaviour was and whether it was broken already in a different way, it will help inform what the solution here should be.
Also, does this really require language negotiation to reproduce?
Comment #28
sukr_s commentedResults of manual testing
10.0.8 - View does not provide the option to delete.
10.1.0
- Without language module enabled, Delete confirmation is shown and clicking Cancel, closes the dialog
- With language module enabled, Error as per screenshot error-on-delete.png
Comment #29
sukr_s commentedAfter further analysis, I've found that the URL generated for delete without language module or language with url detection is
https://d10n.ddev.site/file/1/delete?destination=/admin/content/files&_wrapper_format=drupal_modaland with language module with domain detection is
the issue is that in the second case the destination is a fully qualified url and in the first case it's relative path. Since we have fully qualified URL, the RequestSanitizer removes the destination URL and thus it ends up in getCancelUrl and subsequently throws the error.
Comment #30
sukr_s commented- IS updated
- Fix updated
- also fixes issues #2980527: Domain-based language negotiation strips "destination" URL query argument, causing BigPipe error
Comment #31
sukr_s commentedremoving "needs manual testing" tag. done in #28
Comment #32
smustgrave commentedComment in MR.
Comment #33
sukr_s commentedwithout correcting the assertion, the test will fail. do confirm if you want this to be removed. will the merge happen with test failing?
Comment #39
smustgrave commentedSo going to pivot since the todo and test update is needed here. Lets expand test coverage to make sure it includes scenarios in #2980527: Domain-based language negotiation strips "destination" URL query argument, causing BigPipe error. Which I'll close and move over credit for.
Comment #40
sukr_s commentedThe test case
testBlockPlacementIndicatorin BlockUITest.php has the issue described in #2980527: Domain-based language negotiation strips "destination" URL query argument, causing BigPipe error. This has been fixed. I don't think we need additional test case for this.Comment #41
nicodh commentedWorks for me (I had the issue described in #2980527).
Comment #42
smustgrave commentedFine if we don't expand test coverage. Will let committers decide if needed though.
Comment #43
quietone commentedThanks for the working on improving multi-lingual sites!
An issue summary update removed a large block of testing and explanation that I found useful to help understand this issue. Maybe that should be restored?
I read the comments and MR at #2980527: Domain-based language negotiation strips "destination" URL query argument, causing BigPipe error the fix there is very different from this. That MR was created by a core committer and another core committer worked on this issue. I think we need to get confirmation of which solution is preferred. Apologies if I missed it. For now, I will tag for framework manager review. The other issue also has test and it would help to know if that should be kept or not.
There are also comments in the MR to resolve.
Comment #44
sukr_s commentedrestored original proposed solution
Comment #45
sukr_s commentedComment #46
sleitner commentedsolves the problem. All threads were resolved. The large block of testing was restored.
Comment #47
catchLooks like this needs work based on @quietone's review.
Comment #48
sukr_s commentedComment #49
slawrence10 commentedThis same problem exists in Drupal 10 but wasn't sure how to document it?
Error thrown when trying to delete file entities at /admin/content/files
Turn off URL detection that uses domain at /admin/config/regional/language/detection, clear cache and file entities can be deleted error free.
Comment #50
smustgrave commentedUpdated proposed solution to mention that the todo around https://www.drupal.org/project/drupal/issues/2980527 is also being removed.
Resolved the rest of the threads and believe all feedback has been addressed.
Only request I would make is if the MR can be rebased since it's 800+ commits back.
Comment #51
sleitner commentedRebased
Comment #52
smustgrave commentedThanks believe all feedback has been addressed
Comment #53
berdirFeels like the issue that was closed as a duplicate better (more generically) describes what this is about, while this issue title is just about one specific aspect of that? Maybe we should update it?
Comment #54
quietone commentedFrom #53, Trying for a better title.
Comment #55
catchOne comment on the MR - I think the new logic needs an explanation as to why it's there.
Comment #56
xlyz commentedFrom what I understand the current implementation add the domain to the destination uri so that the user after the POST get redirected to the domain is currently using.
For instance if I have a site in english and italian, each with its own domain, and I'm using the english one, if I try to delete the italian translation of a node the delete link is built with the italian domain, and then destination=english_domain/current_path is added to bring back the user to the current page with the current language. Otherwise he'll switch to the language of the page he has deleted.
Current implementaion seems to create problem:
1. delete file does not works
2. if i try to delete a translation of a node I currently get this error:
(on Drupal 10.5)
The proposed patch is not perfect (to user will switch to the language of the translation that need to edit / delete) but it's still better that the current implementation.
P.S. is a backport to 10.x planned?
Comment #57
charlliequadros commentedA version compatible with Drupal 11.3.2 has been created.
Comment #59
shivansunfire commentedDidn't https://www.drupal.org/project/drupal/issues/3424720 already closed and comitted to 11.1.x fix this problem?